I have data in the following format and want to create a grouped bar plot using facet_grid()
in ggplot2
.
plot.df = data.frame(m = factor(rep(1:3, 9)),
s = factor(rep(rep(1:3, each=3),3)),
var = factor(rep(1:3, each = 9)),
val = rnorm(27))
ggplot(plot.df, aes(x=var, y=val, fill=m)) +
facet_grid(.~s,scales="free") +
geom_bar(position="dodge", stat="identity") +
coord_flip()
Now one of the var
factors has a different scale than the others. Let's say we need the different scale for all cases where var == 3
. We can split it from the rest of the facets like this:
plot.df$select = c(rep(0,18),rep(1,9))
ggplot(plot.df, aes(x=var, y=val, fill=m)) +
facet_grid(select~s,scales="free") +
geom_bar(position="dodge", stat="identity") +
coord_flip()
Is it possible to get a separate axis for val
for these two facet groups? Or is it in general considered bad practice and I should split the plot in two separate plots in the first place?