我想重現情節:如何繪製按月份和日期平均的數據?
從link
我幾乎能做到這一點,但我錯過了什麼:
library(lubridate)
library(ggplot2)
# get the data
dates <- seq(as.Date("2012-01-01"), as.Date("2014-12-30"), by = 1)
series <- seq(from = 1, to = 1095, by = 1)
df<-data.frame(dates,series)
# for aggregation
df$month<-as.numeric(format(df$date, "%m"))
df$week<-week(as.POSIXct(df$date))
df$weekday<-weekdays(as.POSIXct(df$date))
df$days<-as.numeric(format(df$date, "%d"))
df$week_days<-as.numeric(format(df$date, "%w"))
# for plotting
for_plot=aggregate(series ~ + weekday+ month, data =df, FUN=mean)
ggplot(for_plot, aes(x=weekday, y=series)) + geom_line(aes(group=month, color=month),size=2,alpha=0.5)
plo如果你想精確地複製它,你應該從'plot()'函數開始,也許使用'lines()'和'points()'的組合。否則,你試圖複製的論文中的情節的哪些方面? –