首页 > 解决方案 > 如何在ggplot2中删除特定的水平网格线

问题描述

我有一个图表,其中手动设置了标签和中断:

library(ggplot2)
library(tibble)

df <- tibble(date = c(2010, 2015, 2020, 2025, 2030),
         value = c(10, 15, 20, 30, 40))

BREAKS = c(10, 20, 30, 35, 40)
LABELS = c('10', '20', '30', '35', '40')

ggplot()+
  geom_path(data = df,
         aes(date, value))+
  scale_y_continuous(
    breaks = BREAKS,
    labels = LABELS)+
  theme(
    panel.grid.minor = element_blank()
  )

在此处输入图像描述

怎么去掉35对应的网格线?像这样: 在此处输入图像描述

标签: rggplot2

解决方案


推荐阅读