【问题标题】:Plot monthly and annual mean on a single plot在单个地块上绘制月平均值和年平均值
【发布时间】:2015-08-29 09:33:48
【问题描述】:

我想绘制每月和每年的温度。根据这个论坛上的一些例子,我收集了每月的年度数据。但是,聚合创建了按月和年排序的数据。如何从 1995 年 1 月开始在 R 基图或 ggplot 中绘制这些数据?

tt<- rnorm(4018, 5, 8)
date<-seq(as.Date('1995-01-01'),as.Date('2005-12-31'),by = 1)
df<-data.frame(date,tt)
df$Month <- months(df$date)
df$Year <- format(df$date,format="%y")
df1<-aggregate(tt ~ Month + Year , df , mean)

【问题讨论】:

标签: r plot ggplot2


【解决方案1】:

在基础 R 中,您可以执行以下操作:

tt<- rnorm(4018, 5, 8)
date<-seq(as.Date('1995-01-01'),as.Date('2005-12-31'),by = 1)
df<-data.frame(date,tt)
df$Month <- months(df$date)
df$Year <- format(df$date,format="%y")
df1<-aggregate(tt ~ Month + Year , df , mean)

#make a date column
df1$date <- as.Date(paste('01', df1$Month, df1$Year), format='%d %B %y')

#plot tt over the dates made above
plot(df1$date, df1$tt)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多