I am trying to visualize data using ggplot2.
I have 3 facet figures with geombars in each
So, here each facet represents a particular variable that I have used in other graphs where ggplot2 assigns them to fill colors by default.
The faceted plots are black by default.
I can change the fill color for all three panels but haven't found how to change each panel's fill to a different color.
Here is a sample data and code to represent the basic idea:
df = data.frame(matrix(data=c(1,3,1,2,3,1,2,3,2,3,1,2,3,1,2,3,
1,3,2,1,2,2,2,3,3,3,1,1,1,3,3,2),
ncol=2,byrow=TRUE))
dimnames(df)[[2]] =c("x","y")
dodgebars <-
ggplot(data = df,aes(factor(y),fill=factor(x))) +
geom_bar(aes(group=factor(x)),
position="dodge")
facetedbars <-
ggplot(data = df, aes(factor(y))) +
geom_bar(aes(group=x)) +
facet_grid(~x)
How to match the color of each facet to fill its cover in "dodgebars"?