繁体   English   中英

如何使用日期调整 R 中的轴刻度?

[英]How to adjust the axis scale in R with date?

我正在尝试比较两个流域中随时间变化的 pH 值。 对于日期,数据输入读取为“2020-07-17”。 但是,我正在尝试调整 x 和 y 轴以反映 3 到 6 之间的 pH 数据,以及 2020-07-17 和 2000-07-18 之间的时间。 当我尝试使用 xlim/ylim 来调整刻度时,我收到一个关于 POSIXct 的错误,即找不到原点。

目前,我的代码是这样的:

ggplot(W1_new, aes(x=Date, y=pH, color=Treatment) +
  geom_point(pch=19, size=1,alpha = 1) +
  theme_classic()+ theme(legend.title = element_blank())+
  theme(legend.position = c(0.92,0.11))+
  scale_color_manual(labels = c("Ca-treated"),
                     values = c("darkturquoise")) +
  facet_wrap(~Hor)

使轴匹配的正确代码是什么? TIA在此处输入图像描述

scale_x_datetime中使用limits参数

ggplot(W1_new, aes(x=Date, y=pH, color=Treatment) +
geom_point(pch=19, size=1,alpha = 1) +
 scale_x_datetime(date_labels = "%b %d %Y",
               date_breaks = "5 year",
               limits = c(min(W1_new$Date), max(W1_new$Date))) +
theme_classic()+ theme(legend.title = element_blank())+
theme(legend.position = c(0.92,0.11))+
scale_color_manual(labels = c("Ca-treated"),
                 values = c("darkturquoise")) +
facet_wrap(~Hor)

我没有运行代码,但我认为它应该是相同的。 这会很有帮助,但如果您想要确切的代码,请提供示例数据。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM