facet-wrap
ggplot2: facet_wrap strip color based on variable in data set
With a little bit of work, you can combine your plot with a dummy gtable that has the right grobs, d <- data.frame(fruit = rep(c(“apple”, “orange”, “plum”, “banana”, “pear”, “grape”)), farm = rep(c(0,1,3,6,9,12), each=6), weight = rnorm(36, 10000, 2500), size=rep(c(“small”, “large”))) p1 = ggplot(data = d, aes(x = farm, y = weight)) + geom_jitter(position = … Read more
What’s the difference between facet_wrap() and facet_grid() in ggplot2?
The answer below refers to the case when you have 2 arguments in facet_grid() or facet_wrap(). facet_grid(x ~ y) will display x*y plots even if some plots are empty. Ex: library(ggplot2) g <- ggplot(mpg, aes(displ, hwy)) There are 4 distinct cyl and 7 distinct class values. g + geom_point(alpha=1/3) + facet_grid(cyl~class) The above displays 4 … Read more
Annotating text on individual facet in ggplot2
Function annotate() adds the same label to all panels in a plot with facets. If the intention is to add different annotations to each panel, or annotations to only some panels, a geometry has to be used instead of annotate(). To use a geometry, such as geom_text() we need to assemble a data frame containing … Read more