Skip to content

Instantly share code, notes, and snippets.

@mattsedlar
Created October 24, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsedlar/8ec3435c8b472af5312ade1314423e57 to your computer and use it in GitHub Desktop.
Save mattsedlar/8ec3435c8b472af5312ade1314423e57 to your computer and use it in GitHub Desktop.
library(ggplot2)
library(ggthemes)
# assigning notes and values centered around middle C
viola.notes = c(LETTERS[3:7],LETTERS[1:7],LETTERS[1:5])
viola.values = c(seq(-7,9,by=1))
violin.notes = c(LETTERS[7],LETTERS[1:7],LETTERS[1:7],LETTERS[1:2])
violin.values = c(seq(-3,13,by=1))
cello.notes = c(LETTERS[3:7],LETTERS[1:7],LETTERS[1:4])
cello.values = c(seq(-14,1,by=1))
bass.notes = c(LETTERS[5:7],LETTERS[1:7],LETTERS[1:2])
bass.values = c(seq(-19,-8,by=1))
# create dataframe
df = data.frame(instruments=c(rep("viola",17),
rep("violin",17),
rep("cello",16),
rep("double bass",12)),
clef=c(rep("alto",17),
rep("treble",17),
rep("bass",16),
rep("bass",12)),
notes=c(viola.notes,violin.notes,cello.notes,bass.notes),
values=c(viola.values,violin.values,cello.values, bass.values))
# factor instruments from highest to lowest
df$instruments = factor(df$instruments, levels = rev(c("violin","viola","cello","double bass")))
colors = c("#382531","#877975","#BFBD99")
# plot the instruments
ggplot(df, aes(instruments,values, fill=clef,color=clef, label=notes)) +
geom_point(shape=22,size=10) +
# geom_text(color="white") +
coord_flip() +
labs(title="Range of Notes Based on 1st Position",fill="Primary Clef:") +
scale_y_continuous(limits=c(min(df$values),max(df$values)),
breaks=seq(min(df$values),max(df$values),by=1),
labels = c(rep("",19),"Middle C",rep("",13))) +
scale_fill_manual(values=colors) +
scale_color_manual(values=colors,guide=F) +
geom_hline(yintercept = 0) +
theme_hc() +
theme(axis.ticks.x=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position="bottom")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment