-
-
Save briatte/fb6e272bed090a1f7df60378481964a4 to your computer and use it in GitHub Desktop.
function to label facets with letters in ggplot2
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
# 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