Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在ggplot2中使用镶嵌面_包裹_R_Ggplot2_Facet Wrap - Fatal编程技术网

R 在ggplot2中使用镶嵌面_包裹

R 在ggplot2中使用镶嵌面_包裹,r,ggplot2,facet-wrap,R,Ggplot2,Facet Wrap,希望每个绘图具有不同的参数。示例如下: x = c(43,22,53,21,13,53,23,12,32) y = c(42,65,23,45,12,22,54,32,12) df = cbind(x,y) df = as.data.frame(df) meany = mean(y) p = ggplot(df, aes(x=x,y=y, colour=(y > meany))) + geom_point() + geom_hline(yinterce

希望每个绘图具有不同的参数。示例如下:

x = c(43,22,53,21,13,53,23,12,32)
y = c(42,65,23,45,12,22,54,32,12)

df = cbind(x,y)

df = as.data.frame(df)  

meany = mean(y)

p = ggplot(df, aes(x=x,y=y, colour=(y > meany))) + 
      geom_point() +
      geom_hline(yintercept = meany)
p
这很好,在y的平均值处有一条线,线的上方和下方有不同的颜色

我有一个更大的数据框,我想对每个因子级别执行此操作,并使用facet_wrap显示所有图。我不知道如何使ggplot中的颜色和yintercept对于facet_wrap中的每个图形都发生变化

另外,我希望这个图有更多的层,即每个图都将比较不同模型的MSE

谢谢你的帮助。

像这样的吗

DB <- data.frame(F = factor(rep(LETTERS[1:3], each = 20)),
                 x = rnorm(60, 40, 5), 
                 y = rnorm(60, 40, 5))

library(plyr)
library(ggplot2)

DB <- ddply(DB, "F", mutate, ind = y > mean(y))
mns <- ddply(DB, "F", summarise, meany = mean(y))

ggplot(DB, aes(x = x, y = y, color = ind)) +
    geom_point() +
    geom_hline(data = mns, aes(yintercept = meany)) +
    facet_wrap(~ F, nrow = 1)

DB您是否有实际
数据的一小部分。frame
?你读了吗?
p+facet\u wrap(~yourFactor)
是否已经带来了期望的结果?请同时阅读