This vignettes is a brief introduction to the ggguitar package. The graphics are based on ggplot2 and processing on the tidyverse in general.
library(ggguitar) library(tibble) library(ggplot2) # Ignoring warnings options( warn = -1 )
Special thanks to Dr. Hadley Wickham and the crew at RStudio whose work does all of the heavy lifting.
A chord in ggguitar is represented as a vector containing 6 elements. Each element represents a string. A numeric value represents the fret where a finger is placed. Zero represents an open string, NA represents a string not played (either skipped or muted).
A G Major chord can be represented using the following vector.
G_M <- c(3, 2, 0, 0, 0, 3)
The ggguitar method can be used to create the tablature for this chord. The numbers in the vector represent fret positions with zeros indicating open strings. By default the x and y axis are labeled as Strings and Frets along with associated numbers.
ggguitar::tablature('G Major', G_M)
If a given string is not to be played, an NA is used rather than an integer representing the fret number.
B_M <- c(NA, 2, 4, 4, 4, 2) ggguitar::tablature('B Major', B_M)
Both open strings and ignored/muted strings can be included in the same chord.
C_M <- c(NA, 3, 2, 0, 1, 0) ggguitar::tablature('C Major', C_M)
Chords need not be restricted to first position. In the next example, a bar chord further up the neck is represented.
C_M_bar <- c(8, 10, 10, 9, 8, 8) ggguitar::tablature('C Major (bar)', C_M_bar)
Charts can be assigned to variables and then displayed together using grid.arrange.
D_M <- c(NA, NA, 0, 2, 3, 2) F_M7 <- c(NA, NA, 3, 2, 1, 0) e_m <- c(0, 2, 2, 0, 0, 0) a_m <- c(NA, 0, 2, 2, 1, 0) b_m <- c(NA, 2, 4, 4, 3, 2) G_Major <- tablature('G Major', G_M) C_Major <- tablature('C Major', C_M, TRUE, FALSE) D_Major <- tablature('D Major', D_M, FALSE, FALSE) e_minor <- tablature('e minor', e_m) a_minor <- tablature('a minor', a_m, TRUE, FALSE) b_minor <- tablature('b minor', b_m) gridExtra::grid.arrange(G_Major, C_Major, D_Major, a_minor, b_minor, e_minor, ncol = 3)
In place of dots on frets, labels can be assigned. These can contain finger numbers, scale degrees or any other characters of interest.
tablature("A7", c(5, NA, 5, 6, 5, NA), dot_labels=c("Root", NA, "7th", "3rd", "5th", NA))
The appearance of the labels varies depending on the size of the rendered image. You can assign a size for these labels explicitly.
tablature("A7", c(5, NA, 5, 6, 5, NA), dot_labels=c("R", NA, "7", "3", "5", NA), dot_label_size = 5)
Scales can be presented as well.
G_M_scale <- c(3, 0,0,0,NA,NA, NA,2,2,NA,NA,NA, NA,3,4,NA,NA,NA) tablature('G Major Scale', G_M_scale, dot_labels=c(2, 0,0,0,NA,NA, NA, 1,1,NA,NA,NA, NA, 2,3,NA,NA,NA), dot_label_size = 5)
The reverse function - called rev() - in Base-R can be used to render a left-handed version of a chord. If you want the strings on the x-axis, these should be passed using the x_labels parameter.
ggguitar::tablature('G Major (Left-handed)', rev(G_M), x_labels = c(1,2,3,4,5,6))
sessionInfo()
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.