Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to have panel.grid.major in theme under specific angle in ggplot2?

I am wondering if there is a way to rotate panel.grid.major.x lines under specific angle in ggplot2? I've seen in the documentation that it uses element_line but it does not have an angle parameter which corresponds to the rotation in axis.title.x-like functions in the theme element of the ggplot object from ggplot2 package from R?

EDIT

I would like to have additional lines on the plot (as in the attached example below) but instead of adding geom_abline for each line I thought it would be easier to rotate the panel grid. enter image description here

like image 828
Marcin Kosiński Avatar asked Nov 10 '22 02:11

Marcin Kosiński


1 Answers

It's definitely going to be much much easier to use geom_abline than to try to change the way gridlines work with coordinates. You don't need one geom_abline for each line, it takes vectors as slope and intercept. So:

ggplot(mtcars, aes(x = disp, y = mpg)) +
  geom_point() +
  theme_void() +
  geom_abline(slope = 2, intercept = 0:10 * 50 - 800, colour = "grey50")

enter image description here

like image 185
Peter Ellis Avatar answered Nov 15 '22 06:11

Peter Ellis