r - Specifying different axis labels between facets -
i specify breaks , colors 2 facets independently. there way this?
using code
ggplot(data, aes(x = x, y = y)) + geom_point() + scale_y_continuous(breaks = c(0:3, 4, 6, 8)) + facet_wrap(~group, scales = "free")
i can add additional breaks need on bottom facet, don't want these top. in other words, i'd have 0, 1, 2, 3
bottom plot , 0, 2, 4, 6, 8
top plot.
i don't have idea of how specify different colors labels between facets (let me know if should open separate question colors).
one way plot each group separately, lay out plots together:
library(gridextra) p1 = ggplot(data[data$group=="group1",], aes(x = x, y = y)) + geom_point() + scale_y_continuous(breaks = c(0:3, 4, 6, 8)) + facet_wrap(~ group) p2 = ggplot(data[data$group=="group2",], aes(x = x, y = y)) + geom_point() + scale_y_continuous(breaks = c(-1:3)) + facet_wrap(~ group) grid.arrange(p1, p2, ncol=1)
if can come rule programmatically deciding y-breaks, can plots @ once using lapply
. here's simple example. use case, you'll need see if can come rule or rules work plots.
# store plots in list pl = list() pl = lapply(unique(data$group), function(i) { ggplot(data[data$group==i,], aes(x,y)) + geom_point() + facet_wrap(~ group) + scale_y_continuous(limits=c(min(data$y[data$group==i]), max(data$y[data$group==i])), breaks=min(data$y):max(data$y)) }) do.call(grid.arrange, c(pl, ncol=1))
Comments
Post a Comment