I am trying to create a grid of bargraphs that show the average for different species. I am using the iris
dataset for this question.
I summarised the data, melted it into long form long, and tried to use facet_wrap
.
iris %>%
group_by(Species) %>%
summarise(M.Sepal.Length=mean(Sepal.Length),
M.Sepal.Width=mean(Sepal.Width),
M.Petal.Length= mean(Petal.Length),
M.Petal.Width=mean(Petal.Width)) %>%
gather(key = Part, value = Value, M.Sepal.Length:M.Petal.Width) %>%
ggplot(., aes(Part, Value, group = Species, fill=Species)) +
geom_col(position = "dodge") +
facet_grid(cols=vars(Part)) +
facet_grid(cols = vars(Part))
However, the graph I am getting has x.axis labels that are strung across each facet grid. Additionally the clustered graphs are not centered within each facet box. Instead they appear at the location of their respective x-axis label. I'd like to get rid of the x-axis labels, center the graphs, and scale the graphs within each facet.
Here is an image of the resulting graph marked up with my expected output:
dput(df)
or if your data is very largedput(df[1:20,])
. You can edit your question and paste the output. Please surround the output with three backticks (```) for better formatting. It may also be helpful to mock up your expected graph in paint or preview. See How to make a reproducible example for more info.