所以我有以下MWE,一条水平线表示某一天的平均值,这些点是情绪的测量值。
我想在点之间的一天内画一条线而不是点,但该线必须在几天之间休息。我似乎无法弄清楚如何做到这一点 我在this page上尝试了这个示例,但这对我的数据似乎不起作用 我的一个朋友设法为水平线做了这个(他们在天之间有空格),但我似乎无法改变我的代码,让它在几天内完成测量。
MWE:
beeps.MWE <- c(91.188697, 87.846194, 93.166418, 96.249094, 95.495146, 99.362597, 94.373646,
81.995712, 87.626009, 91.880172, 93.112647, 99.349234, 87.073372, 85.161982, 88.119728,
89.738318, 68.891181, 62.504569, 75.131526, 56.035989, 66.035109, 56.012537)
day.MWE <- rep(c(91.35869, 63.17620), each = 11)
loc.MWE <- c(8, 15)
plot(day.MWE, type = "n", pch = 15, cex = 1.5, ylim = c(40, 110), bty = "n",
ylab = "score on PA/NA", xlab = "days of person i", axes = FALSE)
dayUn <- unique(day.MWE)
for (i in seq_along(dayUn))
{
points(which(day.MWE==dayUn[i]),day.MWE[day.MWE==dayUn[i]], type = 'l', lwd = "2")
}
points(1:length(beeps.MWE), beeps.MWE, type = "p")
lines(1:length(beeps.MWE), rep(mean(day.MWE), 22), lwd = "2", lty = 2)
axis(1, at = c(1, 20), labels = c("day 1", "day 2"))
axis(2, las = 1)
这是上述代码的输出:
答案 0 :(得分:1)
您提供的代码几乎就在那里。只需在循环中添加一条线以绘制点之间的线:
for (i in seq_along(dayUn)){
# draw horizontal lines to show the mean per day
points(which(day.MWE==dayUn[i]),day.MWE[day.MWE==dayUn[i]], type = 'l', lwd = "2")
# draw a line that connects points within a day
points(which(day.MWE==dayUn[i]),beeps.MWE[day.MWE==dayUn[i]], lwd = "2", type='l')
}
另请注意,points(x,y,type='l')
与lines(x,y)
相同。更有意义;)