簡體   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