我无法在每个方面制作三条线的刻面自动绘图; 我的目标是绘制5个不同站点的平均温度,最高温度和最低温度;小平面将成为站点和线路的温度,我试过这个:
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
答案 0 :(得分: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")
图表如下: