I have been trying to plot my 2-way interactive boxplots with ggplot2 and I was quite successful so far. Since I want the viewers to be able to compare the results based on them being negative and positive, I figured it would be neat to change the color of gridline at y=0; I searched a lot and I could not find any similar questions online. I even tried to manipulate the theme() feature myself.
I realized that the the minor gridlines cannot have labels and in case minor and major gridlines overlap, the line would inherit the theme features for the major lines. So, I could transform y=0 into a minor gridline without any labels or I could have y=0 as a major line but then the rest would be minor and thus, no labels are shown. (I obviously don't want all of the gridlines to be darker than y=0 because then it would not be significantly obvious.
The chart below shows the first scenario:
p + scale_y_continuous(expand = c(0, 0), breaks = c(-40, 40, -20, 20), minor_breaks = c(0))
+theme(panel.grid.minor.y = element_line(color="#54545B"))
And This chart shows the second scenario:
p + scale_y_continuous(expand = c(0, 0), breaks = seq(-40, 40, 40), minor_breaks = c(-20, 20))
+theme(panel.grid.major.y = element_line(color="#54545B"))
Did anyone have the same issue? Is there any good solution to do this without using Photoshop (manually manipulating the charts!)?
geom_hline(yintercept = 0)
instead. – neilfws