尝试使用其他分组变量向facet_wrap绘图添加平均线

时间:2017-12-04 15:06:45

标签: r ggplot2 facet-wrap geom-hline

我正在尝试用ggplot创建一个散点图。我的数据集由4列组成,其中三列是因子变量,第四列是连续变量。

'data.frame':108 obs。 4个变量:

$名称:因子w / 3级别“Con”,“Tag”,“Vel”:1 2 3 1 2 3 1 2 3 1 ...

$ Model:因子w / 3级别“1”,“2”,“3”:1 1 1 1 1 1 1 1 1 1 ...

$ IndexSeq:int 1 1 1 2 2 2 3 3 3 4 ...

$ Measurement:num 0.736 0.377 0.377 1.072 0.513 ...

plot5<-ggplot(plot.data.test, aes(IndexSeq, Measurement, color=Model)) + geom_jitter()+     
geom_hline(aes(yintercept=Measurement, color=Model), supplot)+
facet_wrap(~plot.data.test$Name)

“Supplot”包含“名称”和“模型”的平均值,因此有9个数据点。我阅读了许多帖子,这些帖子说要在面板图上添加水平均值,您需要单独的data.frame包含聚合测量值。当我遵循所有这些时,我收到以下错误:

Error in `$<-.data.frame`(`*tmp*`, "PANEL", value = c(1L, 2L, 3L, 1L,  : replacement has 108 rows, data has 9

我做错了什么?

干杯!

0 个答案:

没有答案
相关问题