【发布时间】:2021-11-17 18:46:09
【问题描述】:
我有这些时间序列数据,我绘制如下
## simulate ARIMA(1, 0, 0)
set.seed(289805)
x1 <- arima.sim(n = 10, model = list(ar = 0.8, order = c(1, 0, 0)), sd = 1)
set.seed(671086)
x2 <- arima.sim(n = 10, model = list(ar = 0.9, order = c(1, 0, 0)), sd = 1)
set.seed(799837)
x3 <- arima.sim(n = 10, model = list(ar = 0.95, order = c(1, 0, 0)), sd = 1)
set.seed(289805)
x4 <- arima.sim(n = 10, model = list(ar = 0.8, order = c(1, 0, 0)), sd = 3)
set.seed(671086)
x5 <- arima.sim(n = 10, model = list(ar = 0.9, order = c(1, 0, 0)), sd = 3)
set.seed(799837)
x6 <- arima.sim(n = 10, model = list(ar = 0.95, order = c(1, 0, 0)), sd = 3)
set.seed(289805)
x7 <- arima.sim(n = 10, model = list(ar = 0.8, order = c(1, 0, 0)), sd = 5)
set.seed(671086)
x8 <- arima.sim(n = 10, model = list(ar = 0.9, order = c(1, 0, 0)), sd = 5)
set.seed(799837)
x9 <- arima.sim(n = 10, model = list(ar = 0.95, order = c(1, 0, 0)), sd = 5)
set.seed(289805)
x10 <- arima.sim(n = 10, model = list(ar = 0.8, order = c(1, 0, 0)), sd = 10)
set.seed(671086)
x11 <- arima.sim(n = 10, model = list(ar = 0.9, order = c(1, 0, 0)), sd = 10)
set.seed(799837)
x12 <- arima.sim(n = 10, model = list(ar = 0.95, order = c(1, 0, 0)), sd = 10)
xx <- 1:10
# ggplot for x1
plot1 <- ggplot2::ggplot(NULL, aes(y = x1, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x2
plot2 <- ggplot2::ggplot(NULL, aes(y = x2, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x3
plot3 <- ggplot2::ggplot(NULL, aes(y = x3, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x4
plot4 <- ggplot2::ggplot(NULL, aes(y = x4, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x5
plot5 <- ggplot2::ggplot(NULL, aes(y = x5, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x6
plot6 <- ggplot2::ggplot(NULL, aes(y = x6, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x7
plot7 <- ggplot2::ggplot(NULL, aes(y = x7, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x8
plot8 <- ggplot2::ggplot(NULL, aes(y = x8, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x9
plot9 <- ggplot2::ggplot(NULL, aes(y = x9, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x10
plot10 <- ggplot2::ggplot(NULL, aes(y = x10, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x11
plot11 <- ggplot2::ggplot(NULL, aes(y = x11, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# ggplot for x12
plot12 <- ggplot2::ggplot(NULL, aes(y = x12, x = xx)) + ggplot2::geom_line(color = "#F2AA4CFF") + ggplot2::geom_point(color = "#101820FF") + xlab('lb') + ylab('RMSE') + ggplot2::theme_bw()+ ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
# plot in a 3 by 5 grid by using plot_layout
plot1 + plot2 + plot3 + plot4 + plot5 + plot6 + plot7 + plot8 + plot9 + plot10 + plot11 + plot12 + patchwork::plot_layout(ncol = 3, byrow = TRUE)
我现在想用facet_grid 对其进行整容,我尝试如下
df <- data.frame(xx, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)
reshapp <- reshape2::melt(df, id = "xx")
NEWDAT <- data.frame(y = reshapp$value, x = reshapp$xx, sd = rep(c(1,3,5,10), each = 3), phi = rep(c(.8, .9, .95), 4))
ggplot(NEWDAT, aes(x = x, y = y)) + geom_line() + geom_point() + facet_grid(sd ~ phi, scales = "free_y") +
theme_bw() + ggplot2::scale_y_continuous(expand = c(0.0, 0.00))
我想要什么
如何使Facet_Grid Plot 成为Grid_Arranged Plot 的样子?
指针
可以看到,第一个系列中的lowest 数据点是-0.2505125,而highest 是4.6956397。在Facet-Grid Plot、lowest is -20+ 和highest is 30+。
【问题讨论】:
-
有趣 - 显然你在一个月前遇到了同样的陷阱,就像我昨天一样:) 请参阅 stackoverflow.com/q/69863292/7941188 - 问题是数据框中的错误重复。我想你现在可以删除那个问题了吗?
-
当然,我的意思是这个问题。希望能帮到你
-
悬赏问题无法删除
-
我会等到它过期,然后我会删除它。
标签: r ggplot2 reshape2 facet-grid