2017-07-31 35 views
2

我無法在每個面上製作帶有三條線的多面自動繪圖; 我的目標是繪製來自5個不同站的平均,最高和最低溫度;面將是車站和線路的溫度,我嘗試這樣做:使用autoplot動物園的多面圖和多線圖

autoplot.zoo(apply.quarterly(new_temp1[,c(7:14)], colMeans)) + 
    geom_line(col="red") + 
    geom_line(aes(apply.quarterly(new_temp2[,c(7:14)], colMeans))) 

但是卻對我說:

Error in order(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : 
    argument 3 is not a vector 
In addition: Warning message: 
In (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, : 
    row names were found from a short variable and have been discarded 

回答

2

我不能讓你的數據運行,所以我做了一些簡單的時間序列數據來說明如何將geom_line()和facet_wrap()一起應用。 dplyr軟件包對於以簡潔的格式獲取數據非常必要,以便於繪圖。

df <- data.frame(station = rep(LETTERS[1:5], each = 5), 
     date = rep(seq(1,5), times = 5), 
     mean_T = rnorm(25, mean = 75, sd = 2), 
     min_T = mean_T - 20, 
     max_T = mean_T + 20) 

library(dplyr) 
newdf = gather(df, key = type , value = temp, mean_T, min_T, max_T) 

ggplot(newdf, aes(x = date)) + 
    geom_line(aes(y = temp, color = type)) + 
    facet_wrap(~ station) + 
    xlab("date") + 
    ylab("Temperature") + 
    ggtitle("Temperature at Stations") 

該圖是這樣的:

enter image description here

+0

非常感謝,我給它一個嘗試,讓我們來看看,如果我能得到它與XTS工作 –