Last active
March 28, 2019 07:49
-
-
Save padpadpadpad/dc1f4520e4f9530b2c70fed0e4a425e9 to your computer and use it in GitHub Desktop.
function to label facets with letters in ggplot2
This file contains 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
# load package | |
library(ggplot2) | |
# write function | |
label_facets <- function(string){ | |
len <- length(string) | |
string = paste('(', letters[1:len], ') ', string, sep = '') | |
return(string) | |
} | |
# draw example plots | |
ggplot(mpg, aes(displ, hwy)) + | |
geom_point() + | |
facet_wrap(~manufacturer, labeller = labeller(manufacturer = label_facets)) | |
ggplot(mpg, aes(displ, hwy)) + | |
geom_point() + | |
facet_wrap(~class, labeller = labeller(class = label_facets)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment