我有跟随的data.frame:
P value
1 -1.68376331
0.99 -0.41567108
0.96 0.23841294
0.96 -0.22990539
0.96 -0.09554575
0.955 1.67393163
0.82 -0.62701762
0.81 1.32506612
0.81 0.10928334
0.78 0.55526814
0.78 0.22339582
0.70 -0.70335192
0.69 1.34438953
0.68 -0.09821771
0.67 0.33202775
我想绘制每组三个(按P列顺序)值的平均值。我希望它们沿着x轴绘制,以便计算的第一组平均值是最左边的点,第二组平均值是第二个最左边的点,等等。有谁知道如何做到这一点?
答案 0 :(得分:0)
您可以尝试:
ggplot(d, aes(V1, V2)) + geom_point() + theme_bw() +
stat_summary(fun.y = "mean", colour = "red", size = 2, geom = "point") +
stat_summary(fun.y = "mean", geom = "line")
但为什么不在这个问题上使用简单的箱形图:
boxplot(V2 ~ V1, d)
您可以使用点添加方法:
means <- aggregate(d$V2, list(d$V1), mean)
points(means$x, col="red", pch=18)
您的数据
d <- structure(list(V1 = c(1, 0.99, 0.96, 0.96, 0.96, 0.955, 0.82,
0.81, 0.81, 0.78, 0.78, 0.7, 0.69, 0.68, 0.67), V2 = c(-1.68376331,
-0.41567108, 0.23841294, -0.22990539, -0.09554575, 1.67393163,
-0.62701762, 1.32506612, 0.10928334, 0.55526814, 0.22339582,
-0.70335192, 1.34438953, -0.09821771, 0.33202775)), .Names = c("V1",
"V2"), class = "data.frame", row.names = c(NA, -15L))