R 尝试使用ggplot删除x轴下方的轴
我不熟悉R 尝试使用ggplot删除x轴下方的轴,r,ggplot2,R,Ggplot2,我不熟悉ggplot,正在尝试使用它绘制两行。但是我的x轴看起来很奇怪,现在我想把它去掉。这是我的密码 ggplot(BJ11, aes(Date, mean,group=1)) + geom_line(aes(color = "stateair daily values")) + geom_line(data = bjvalue2, aes(color = "CNEMC values")) 以下是我的数据: > head(BJ11)
ggplot
,正在尝试使用它绘制两行。但是我的x轴看起来很奇怪,现在我想把它去掉。这是我的密码
ggplot(BJ11, aes(Date, mean,group=1)) +
geom_line(aes(color = "stateair daily values")) +
geom_line(data = bjvalue2,
aes(color = "CNEMC values"))
以下是我的数据:
> head(BJ11)
Date min max mean
1 2015-01-01 6 154 54.58333
2 2015-01-02 12 157 63.54167
3 2015-01-03 147 322 209.25000
4 2015-01-04 106 360 201.16667
5 2015-01-05 9 186 90.87500
6 2015-01-06 10 121 43.16667
> head(bjvalue2)
Date mean
1 2015-01-01 43
2 2015-01-02 52
3 2015-01-03 150
4 2015-01-04 176
5 2015-01-05 92
6 2015-01-06 40
如何删除“日期”上方的黑色粗轴和x轴?另一个选项是修复x轴,而不是删除它。我知道这不是你们的问题,但ggplot在处理日期轴方面非常好,所以我想知道你们是否将日期作为角色?如果您有,则可以使用带有ymd()的例如库(lubridate)
ggplot(BJ11, aes(Date, mean, group=1))+
geom_line(aes(color = "stateair daily values"))+
geom_line(data = bjvalue2, aes(color = "CNEMC values"))+
theme(axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.line.x = element_blank())
我猜为了简单起见,您的group=1可以省略
另外,在您的最后一行中,我个人更喜欢在aes中定义x和y轴,以确保R以您想要的方式处理数据。将以下内容添加到绘图
主题(axis.title.x=element\u blank(),axis.text.x=element\u blank(),axis.ticks.x=element\u blank(),axis.line.x=element\u blank())
我明白了!非常感谢。如果@NColl解决了问题,则应将其作为答案,以便将来更容易看到