Barplot in R/ggplot with multiple factors
Try multi-level facets:
df2 <- melt(df1, id.vars=c("Loc", "Type"))ggplot(data=df2, aes(x=value, fill=Type)) + geom_bar() + facet_wrap(~ Loc + variable, nrow=1)
Or alternatively, facet_grid
, which I think looks better but doesn't quite match your sketch:
df2 <- melt(df1, id.vars=c("Loc", "Type"))ggplot(data=df2, aes(x=value, fill=Type)) + geom_bar() + facet_grid(Loc ~ variable)
Finally, borrowing from this post, you could try to better distinguish the locations by color (clearly color scheme could use some work, but you get the point):
df2 <- melt(df1, id.vars=c("Loc", "Type"))ggplot(data=df2, aes(x=value, fill=Type)) + geom_rect(aes(fill=Loc),xmin =-Inf,xmax=Inf,ymin=-Inf,ymax=Inf,alpha = 0.1) + geom_bar() + facet_wrap(~ Loc + variable, nrow=1)
If you want to actually have separate panels for each location, I think you'll have to use generate your own grid viewports and grobs. There was a package ggextra
that did stuff like this, but it doesn't seem to be available for the most recent R versions.