How can I suppress the vertical gridlines in a ggplot2 plot?

前端 未结 5 1114
无人及你
无人及你 2020-12-01 04:14

I am building a bar chart for which bars suffice as indications of horizontal (x) placement, so I\'d like to avoid drawing the superfluous vertical gridlines.

I unde

5条回答
  •  爱一瞬间的悲伤
    2020-12-01 04:31

    Option 1:

    data_df <- data.frame(x = 1:10, y = c(3,5,2,5,6,2,7,6,5,4))
    
    ggplot(data_df, aes(x, y)) +
      geom_bar(stat = 'identity') +
      theme(panel.background = element_rect(fill = "white"))
    

    Option 2:

    data_df <- data.frame(x = 1:10, y = c(3,5,2,5,6,2,7,6,5,4))
        
    ggplot(data_df, aes(x, y)) +
          geom_bar(stat = 'identity') +
          theme(
            panel.grid.major.x = element_blank(),
            panel.grid.minor.x = element_blank(),
            panel.grid.major.y = element_blank(),
            panel.grid.minor.y = element_blank()
          )
    

提交回复
热议问题