简体   繁体   English

如何在GGPLOT theme_classic()中启用x轴和y轴线

[英]How to enable x-axis and y-axis line in GGPLOT theme_classic()

With this code: 使用此代码:

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()

I expect to get image like this: 我希望得到这样的图像:

在此处输入图片说明

But how come I get this instead: 但是我怎么得到这个呢?

在此处输入图片说明

Notice the missing x-axis an y-axis line. 注意缺少的x轴和y轴线。 How can I enable it? 如何启用它?

This is theme_classic() specific issue. 这是theme_classic()特定问题。

Here is a solution from this GitHub issue 这是此GitHub 问题的解决方案

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'))

Edit 编辑

If you are running into this issue, updating ggplot2 should fix the issue, and the solution above shouldn't be necessary. 如果您遇到此问题,则更新ggplot2应该可以解决该问题,并且上面的解决方案不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R中x轴和y轴ggplot的标签尺寸 - Size of labels for x-axis and y-axis ggplot in R ggplot:在x轴上绘制bin,在y轴上绘制平均值 - ggplot: Plotting the bins on x-axis and the average on y-axis 在 R 基础 plot 和 GGPlot2 中的 x 轴和 y 轴上显示相应的虚线 - Show corresponding dash line on x-axis and y-axis in R base plot and GGPlot2 如何通过折线图将y轴上的所有点连接到同一组ggplot的x轴点 - How to connect all points on a y-axis to x-axis points of same group ggplot through a line graph 如何使用 ggplot 在 x 轴上绘制日期,在 y 轴上绘制价格表和属性? - How can I plot date on x-axis and price list on y-axis and attribute by using ggplot? 如何在 ggplot2 中让 x 轴在零处截取 y 轴 - How to get the x-axis to intercept the y-axis at zero in ggplot2 如何在 ggplot 上制作一个箱线图,其中我的 x 轴有两列,我的 y 轴有两列? - How to make a boxplot on ggplot with two columns for my x-axis and two columns for my y-axis? 如何扩展x轴和y轴并缩小ggthemes :: theme_tufte()中的差距 - How to extend x-axis and y-axis and narrow the gap in ggthemes::theme_tufte() R程序-如何避免ggplot在x轴和y轴上重新排序 - R program-how to avoid ggplot re-order in both x-axis and y-axis R ggplot2:如何使x轴线不与y轴重叠? - R ggplot2: how to make x-axis lines not overlapping y-axis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM