I am trying to overlay a line plot onto a barplot. I can plot both separately :
##plot sites
ggplot(graph, aes(x = Month, y = Anopheles_pos))
+ geom_col(size = 1, color = "darkblue", fill = "white")
##plot line
ggplot(graph, aes(x = Month, y = Mean_EVI)) +
geom_line(size = 1.5, color = "blue", group = 1)
However when I try to plot the line onto the barplot, it is a flat line at the bottom. I tried to deal with the issue by fixing the second y axis (on the right) to be the same scale as the line, but this has not fixed how the line plots.
##plot together
ggplot(graph) +
geom_col(aes( x = factor(Month, levels = month.name), y = Anopheles_pos), size = 1,
color = "darkblue", fill = "white") +
geom_line(aes(x = factor(Month, levels = month.name), y = Mean_EVI), size = 1.5,
color = "red", group = 1) +
scale_y_continuous(sec.axis = sec_axis(~./50, name = "Mean_EVI"))
One small other issue is I can't figure out how to make the x axis 0-100 as the Anopheles_pos values are percentages.
Thanks in advance!!
DATA:
Mean_EVI : c(0.5687068, 0.5663895, 0.5653846, 0.6504931, 0.584727, 0.5799395, 0.617363, 0.581645, 0.6190386, 0.5208025, 0.6097692, 0.5689)
Anopheles_pos : c(33L, 42L, 38L, 31L, 54L, 47L, 22L, 15L, 2L, 15L, 12L, 19L)