The plot_fretboard
function can be used to create general fretboard diagrams directly in R using ggplot and plot_chord
specifically produces single chord diagrams, but this vignette shows how to create a standalone chord chart using LilyPond. Instead of using tab
to render a score to pdf that may contain a chord chart at the top of the first page, you can use render_chordchart
. This function creates the necessary LilyPond file and sends it to LilyPond for final rendering.
For consistency, render_chordchart
takes chord input in the same way that the score
function does, as a named character vector. The chords and their names are in the same format.
Filter the guitarChords
dataset down to chords:
library(dplyr)
chords <- filter(
guitarChords,
root %in% c("c", "f") &
id %in% c("7", "M7", "m7") &
!grepl("#", notes) & root_fret <= 12
) %>%
arrange(root, id)
chords <- setNames(chords$fretboard, chords$lp_name)
head(chords)
#> c:7 c:7 c:7 c:7
#> "x;3;2;3;1;x;" "x;3;5;3;5;3;" "x;3;2;3;1;3;" "8;10;8;9;8;8;"
#> c:7 c':7
#> "8;x;8;9;8;x;" "x;x;10;9;11;8;"
The filtering above results in 41 chords. The size of the fretboard diagrams is increased below with size = 2
. Like lilypond
and the render_*
functions that wrap around it for rendering music scores, render_chordchart
also takes the header
and paper
named list arguments. Once the named chord vector is ready, rendering the chord chart is as simple as the following.
hdr <- list(
title = "Dominant 7th, major 7th and minor 7th chords",
subtitle = "C and F root"
)
render_chordchart(chords, "out.png", 2, hdr, list(textheight = 175))
The chord chart template must be kept to one page.