Add abcd labels on ggplot facets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
#example dataset: | |
mydata = data.frame(x = 1:10, y=1:10 | |
, cat = c(rep('first', 3), rep('second', 3), rep('third', 4))) | |
#create (a), (b), ... | |
my_plotlabels = paste0('(', letters, ') ') | |
#paste plot labels together with the levels of the variable used for faceting | |
levels(mydata$cat) = paste0(my_plotlabels[1:length(levels(mydata$cat))] | |
, levels(mydata$cat)) | |
ggplot(mydata, aes(x=x, y=y))+ | |
facet_wrap(~cat)+ | |
geom_point(size=2, shape=7)+ | |
theme_bw() |