How can I add just horizontal gridlines in a ggplot in R

2k Views Asked by At

Image Link here

I want code to add just the horizontal gridlines. I also cant see max values clearly when viewing, is there a way to add extra margin on the side.

1

There are 1 best solutions below

0
Magnus Nordmo On

Here is an example. theme_void() makes the gridlines disappear (along with the majority of plot items). However, we can manually edit the theme() if we place the function after theme_void().

library(tidyverse)

ggplot(mtcars,aes(mpg,hp)) + 
  geom_point() + 
  theme_void() + 
  theme(panel.grid.major.y = element_line(),
        panel.grid.minor.y = element_line())

Created on 2022-10-05 by the reprex package (v2.0.1)