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))
## R version 3.3.2 (2016-10-31) ## Platform: x86_64-apple-darwin13.4.0 (64-bit) ## Running under: OS X El Capitan 10.11.6 ## ## locale: ##  C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 ## ## attached base packages: ##  stats graphics grDevices utils datasets methods base ## ## other attached packages: ##  ggplot2_2.2.0 tibble_1.2 ggguitar_0.1.1 ## ## loaded via a namespace (and not attached): ##  Rcpp_0.12.8 digest_0.6.10 rprojroot_1.1 assertthat_0.1 ##  plyr_1.8.4 grid_3.3.2 gtable_0.2.0 backports_1.0.4 ##  magrittr_1.5 scales_0.4.1 evaluate_0.10 stringi_1.1.2 ##  lazyeval_0.2.0 rmarkdown_1.3 tools_3.3.2 stringr_1.1.0 ##  munsell_0.4.3 yaml_2.1.14 colorspace_1.3-2 htmltools_0.3.5 ##  knitr_1.15.1 gridExtra_2.2.1