【问题标题】:Remove specific vertical gridline from ggplot从 ggplot 中删除特定的垂直网格线
【发布时间】:2019-05-22 08:01:50
【问题描述】:

基本上我想删除我的情节中的一些垂直网格线。请注意,这不是 How can I suppress the vertical gridlines in a ggplot2 plot? 的重复,因为这个 subjet 是要删除所有垂直网格线。

这是一个最小的可复制示例:

ggplot(diamonds) +
  aes(x = price) + 
  geom_histogram(
    color = 'white',
    fill = 'blue4'
    ) + 
  theme_minimal() 

我想抑制与标签无关的垂直网格线(5000、10000、...)。

我试过了:

p +
 theme(
   panel.grid.major.x = element_blank()
   )

但它实际上与我正在寻找的相反:它删除与标签关联的行,而不是“无用”的行。

【问题讨论】:

  • panel.grid.minor.x = element_blank()
  • @Humpelstielzchen 抱歉,回答时没有注意到您的评论。你在 30 秒前发布了它。您可以将其发布为答案,我将删除我的。
  • 没问题的家伙。继续。
  • 感谢你们俩。它完美地工作

标签: r ggplot2


【解决方案1】:

尝试使用panel.grid.minor.x

library(ggplot2)

ggplot(diamonds) +
  aes(x = price) + 
  geom_histogram(
    color = 'white',
    fill = 'blue4'
  ) + 
  theme_minimal() +
  theme(panel.grid.minor.x = element_blank())

【讨论】:

    猜你喜欢
    • 2016-09-22
    • 2012-04-04
    • 1970-01-01
    • 2010-12-22
    • 2019-02-14
    • 2012-08-01
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    相关资源
    最近更新 更多