【问题标题】:Changing POSICXT x-axis to selected labels将 POSICXT x 轴更改为选定的标签
【发布时间】:2021-08-28 02:31:54
【问题描述】:

我有 19 天(9 月 11 日至 30 日)每 30 分钟采集一次的温度数据,我想更改我的 x 轴标签以显示每天或每隔一天,并将其标记为“第 1 天”、“第 1 天” 3", (...),而不是仅按日期标记的三天(“Sep 14”),如下一个链接所示:温度图。

时间数据属于 POSIXCT 类。我附上了我使用的 ggplot 编码。我要离开 #scale_x_datetime 来展示我失败的解决方案之一。

hoboplot <- ggplot(hobo, aes(x=time, y=Temperatura, color=Tratamiento))+
  geom_path(size=0.86)+
  scale_color_manual(values=c("#2166AC", "#92C5DE", "#FDDBC7", "#D6604D", "#B2182B"))+
#  scale_x_datetime(labels=c("1", "3", "5", "7", "9", "11", "13", "15", "17", "19"),
#                 breaks = c(1, 3, 5, 7, 9, 11, 13, 15, 17, 19))+
  theme_classic(base_size=18)+
  labs(x="Días", y="Temperatura (°C)")+
  geom_hline(yintercept=10, linetype="dashed", color = "#2166AC")+
  geom_hline(yintercept=14, linetype="dashed", color = "#92C5DE")+
  geom_hline(yintercept=18, linetype="dashed", color = "#FDDBC7")+
  geom_hline(yintercept=22, linetype="dashed", color = "#D6604D")+
  geom_hline(yintercept=26, linetype="dashed", color = "#B2182B")+
  theme(legend.position = "right")+
  guides(color=guide_legend(reverse=TRUE))  

如果有任何帮助,我将不胜感激!

【问题讨论】:

    标签: r ggplot2 axis-labels posixct


    【解决方案1】:

    尝试使用 -

    + scale_x_datetime(date_breaks = '2 days', 
                       labels  = function(x) paste('Day', as.Date(x) - min(as.Date(x), na.rm = TRUE) + 1))
    

    【讨论】:

      猜你喜欢
      • 2021-04-08
      • 2021-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 2020-08-04
      • 1970-01-01
      相关资源
      最近更新 更多