【问题标题】:How to enable x-axis and y-axis line in GGPLOT theme_classic()如何在 GGPLOT theme_classic() 中启用 x 轴和 y 轴线
【发布时间】:2016-07-11 14:08:20
【问题描述】:

使用此代码:

library(ggplot2)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
p <- ggplot(ToothGrowth, aes(x=dose, y=len, color=dose, shape=dose)) + 
  geom_jitter(position=position_jitter(0.2))+
  labs(title="Plot of length  by dose",x="Dose (mg)", y = "Length")
p + theme_classic()

我希望得到这样的图像:

但我怎么会得到这个:

请注意缺少的 x 轴和 y 轴线。 如何启用它?

这是theme_classic() 特定问题。

【问题讨论】:

  • 好的,我也一样:R version 3.3.0ggplot2_2.1.0
  • 如果您查看theme_classic 的定义,您会发现axis.line.x 和axis.line.y 都设置为element_blank。要么自己改变这个定义,要么你可以在 survminer 包中使用 theme_classic2。

标签: r plot ggplot2


【解决方案1】:

这是来自此 GitHub 的解决方案 issue

p + theme_classic() +
    theme(axis.line.x = element_line(colour = 'black', size=0.5, linetype='solid'),
          axis.line.y = element_line(colour = 'black', size=0.5, linetype='solid'))

编辑

如果您遇到此问题,更新ggplot2 应该可以解决此问题,并且不需要上述解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多