以r为单位绘制一年一个月的时间序列数据

以r为单位绘制一年一个月的时间序列数据,r,plot,ggplot2,time-series,R,Plot,Ggplot2,Time Series,需要在r中绘制时间序列数据的帮助。Y是温度,X是日期(现在的格式为%d-%m-%Y),需要类似以下的绘图: 我试过: 单变量温度 ggplot 但是格式不正确 任何帮助都是值得感激的 谢谢 德维 库(ggplot2) #模拟温度数据 temp创建一个适当的可复制示例,以及dput您使用的数据请查看。还可以使用ctrl-g在问题中插入图形(而不是链接到问题)。非常感谢您的快速回复!只是为了添加我使用的数据集,它的日期格式为“%d-%m-%y”和temp1,所以这里我们计算每个月的temp平均值,

需要在r中绘制时间序列数据的帮助。Y是温度,X是日期(现在的格式为%d-%m-%Y),需要类似以下的绘图:

我试过:

单变量温度 ggplot 但是格式不正确

任何帮助都是值得感激的

谢谢 德维

库(ggplot2)
#模拟温度数据

temp创建一个适当的可复制示例,以及
dput
您使用的数据请查看。还可以使用ctrl-g在问题中插入图形(而不是链接到问题)。非常感谢您的快速回复!只是为了添加我使用的数据集,它的日期格式为“%d-%m-%y”和temp1,所以这里我们计算每个月的temp平均值,并绘制2011年的temp?因此,在给定的代码中,我应该使用我的temp at place?Hi@devijayakumar,我认为您所指的平均值是我试图制作一些假温度来模拟您发布的图像。可能没有必要以这种方式构建数据。基本上,我只是用随机数的平均值为一年中的每一天创建了一个温度。所以,我有365个温度,每个温度都与特定的日期有关。我认为您是正确的,尽管我不知道您的数据集“r”是什么样子。无论您的数字温度数据在哪里,都应该是一年中每天一个值,将这些值替换为
temp.avg
@Jason..非常感谢您…我的数据文件就像2011年365天内每天的可变温度,需要是全年瞬时dteday季节yr mnth的时间序列图温度假日工作日工作日天气温度2011-01-01春季01假周六多云/多雾0.344167 atemp hum风速休闲注册cnt 10.363625 0.805833 0.160446 331 654 985
temperature = ts(r$temp, frequency = 12, start = 2011) plot(temperature, xaxt = "n") tsp = attributes(temperature)$tsp dates
= seq(as.Date("2011-01-01"), by = "month", along = temperature) axis(1, at = seq(tsp[1], tsp[2], along = temperature), labels = format(dates, "%m-%y"))
gg2=ggplot(r,aes(mnth,temp)) + geom_line() 
windows() 
print(gg2)
library(ggplot2)

# Simulated temperature data
temp <- runif(75)

temp.avg <- vector()

x <- 365

for(i in 1:x){
  if(i <= round(.33 * x)) {
    temp.avg[i] <- mean(sample(temp, 15, replace = TRUE))
  } else if (i <= round(.66 * x)) {
    temp.avg[i] <- abs(log(mean(sample(temp, 15, replace = TRUE))))
  } else {
    temp.avg[i] <- mean(sample(temp, 15, replace = TRUE)) * (i / x) + .15
 }
 }

 # Generate sequence of days in Date format "%d-%m-%y"
 from <- as.Date("01-1-11 12:00:00 EDT", "%d-%m-%y")
 to <- as.Date("31-12-11 12:00:00 EDT", "%d-%m-%y")
 times <- seq.Date(from, to, 1)

 # Put dates and temperatures into data frame
 Temperature_data <- data.frame(date = times, temp = temp.avg)

 # Plot in ggplot
 ggplot(Temperature_data, aes(date, temp)) + 
   geom_line() + 
   ylim(c(0, 1)) + 
   xlab("") + 
   ylab("Temperature") +
   scale_x_date(date_breaks = "1 month", date_labels = "%b %y") +
   theme(axis.text.x = element_text(angle = 90, hjust = 1)) + 
   ggtitle("Temperature fluctuations in 2011")