I am trying to produce a histogram with y-axis for different subsets of the data.
I have been following the instructions from here: How to automatically adjust the width of each facet for facet_wrap?
But I cannot seem to get the tick marks on the axis to work.
score <- rep(c(0,1,2,3,4,5,6,7,8), c(20424, 1636, 1864, 989, 397, 174, 69, 18, 4))
damage <- rep(c("No damage", "damage"), c(20424, 5151))
damage <- ordered(damage, c("No damage", "damage"))
df <- data.frame(score, damage)
library(ggplot2)
library(ggforce)
#The following produces the graph as I would like it but there are no ticks or tick labels
#on the x-axis
df %>%
ggplot(aes(x = score)) +
geom_histogram(binwidth = 1) +
scale_x_discrete(name = "Score") +
scale_y_continuous(name = "") +
ggforce::facet_row(vars(damage), scales = 'free', space = 'free')
##Whereas this gives me the tick marks and labels but messes up my graph
df %>%
ggplot(aes(x = score)) +
geom_histogram(binwidth = 1) +
scale_x_discrete(name = "Score",
limits = c(0,1,2,3,4,5,6,7,8)) +
scale_y_continuous(name = "") +
ggforce::facet_row(vars(damage), scales = 'free', space = 'free')
I have tried many permutations, with and without using the ggforce::facet_row option, but I just don't seem to be able to get it to work.
Any suggestions would be greatly appreciated.