library(ggplot2)
library(dplyr)
library(pichor)

Built-in data with information about some of the keys on a piano:

Details for drawing a diagram of a piano:

ggpiano(keys_chords)

Add key labels:

ggpiano(keys_chords, labels = TRUE)

Highlight certain keys:

keys_chords %>% 
  highlight_keys(keys = c(7, 10, 14)) %>%
  ggpiano(labels = TRUE)

Work with chords:

Highlight chords:

keys_chords %>% 
  highlight_chord(chord = chrd_Fsm) %>%  # root form by default
  ggpiano()

keys_chords %>% 
  highlight_chord(chord = chrd_Fsm, highest_tone = "A") %>% 
  ggpiano()

Work with chord inversions:

chrd_Bm <- construct_chord_minor(root_tone = "B")
get_keys(chord = chrd_Bm)
#> [1] 12 15 19
get_keys_inversion(chord = chrd_Bm, inversion = 0)
#> [1] 12 15 19
get_keys_inversion(chord = chrd_Bm, inversion = 1)
#> [1]  3  7 12
get_keys_inversion(chord = chrd_Bm, inversion = 2)
#> [1]  7 12 15

Highlight chord inversions:

keys_chords %>% 
  highlight_chord(chord = chrd_Bm, inversion = 0L) %>% 
  ggpiano()

keys_chords %>% 
  highlight_chord(chord = chrd_Bm, inversion = 1L) %>% 
  ggpiano()

keys_chords %>% 
  highlight_chord(chord = chrd_Bm, inversion = 2L) %>% 
  ggpiano()