【发布时间】:2021-12-26 02:33:50
【问题描述】:
我想ggplot 和facet_grid 在这种我的数据类型上包含一个带有[list of vectors][1] 的列,就像这个data in this answer 和this answer 一样。
set.seed(1)
df <- data.frame(xx = 1:10, x1 = rnorm(10), x2 = rnorm(10), x3 = rnorm(10), x4 = rnorm(10), x5 = rnorm(10), x6 = rnorm(10), x7 = rnorm(10), x8 = rnorm(10), x9 = rnorm(10), x10 = rnorm(10), x11 = rnorm(10), x12 = rnorm(10))
reshapp <- reshape2::melt(df, id = "xx")
new_df <- data.frame(y = reshapp$value, x = reshapp$xx, sd = rep(rep(c(sd = 1, sd = 3, sd = 5, sd = 10), each = 10), each = 3), phi = rep(rep(list(c(0.4, 0.4), c(0.45, 0.45), c(0.35, 0.6)), each = 10), 4))
new_df$sd <- factor(new_df$sd, levels = new_df$sd, labels = paste("sd ==", new_df$sd))
我在R 代码Error in factor(phi, levels = phi, labels = paste("phi ==", phi)) : object 'phi' not found. 的这个阶段收到此错误消息
我想如果我能够解决这个错误,我就可以继续前进。
new_df$phi <- with(new_df, factor(phi, levels = phi, labels = paste("phi ==", phi)))
ggplot(new_df, aes(x = reshapp$xx, y = reshapp$value)) + geom_line() + geom_point() + scale_y_continuous(expand = c(0.0, 0.00)) + labs(x = 'Time', y = 'Series') + facet_grid(sd ~ phi, scales = "free_y", labeller = label_parsed) + theme_bw()
如何摆脱这个错误:Error in factor(phi, levels = phi, labels = paste("phi ==", phi)) : object 'phi' not found
我希望输出类似于,只是0.8 将是(0.4, 0.4),0.9 将是(0.45, 0.45) 和0,95 将是(0.35, 0.6)。 .
【问题讨论】:
-
如果您需要更多说明以便更好地理解我的问题,请在评论中提问。
标签: r ggplot2 facet-grid