加入年份和儒略日作为 R 中的日期列并绘制它

Join year and julian day as a date column in R and plot it

我有一些数据,其中一列代表一年中的某一天,另一列代表一年。例如,让我们考虑这个虚拟数据:

temp <- rep(runif(730,15,40))
doy <- rep(c(1:365),2)
year <- c(rep(2015,365), rep(2016,365))

我想加入 doy 和 year 作为日期列(2015-365 格式)。是否可以处理这种日期格式? ggplot或基本函数plot如何处理?

要将儒略日期转换为日期对象,请使用 %j 格式。例如:

temp <- rep(runif(730,15,40))
doy <- rep(c(1:365),2)
year <- c("2015","2016")

jdate<-as.Date(paste(year, doy, sep="-"),"%Y-%j") 
df<- data.frame(jdate, temp)

library(ggplot2)
f<-ggplot(df, aes(x=jdate, y=temp))
f+ geom_point() + scale_x_date(date_breaks="6 week", date_labels="%Y-%j")