我正在尝试将一些平均值绘制到包含三组的箱线图上。我的代码生成了正确的箱线图,但无法绘制平均值。我已经对其他数据集/csv 文件尝试了相同的代码,并且效果很好,因为我既有箱线图又有平均值。
这是箱线图的代码:
boxplot(siteD$Average_Ground ~ siteD$Sampling_Period, notch=F)
我检查了这两个变量,它们的长度相等。
这是绘制平均值的代码:
meanz <- tapply(siteD$Average_Ground, siteD$Sampling_Period, mean, na.rm=T)
points(seq(1, nlevels(siteD$Sampling_Period)), meanz,
col = "red3", pch = 3, lwd = 2, cex = 1.2)
尝试绘图时,出现以下错误:xy.coords(x, y) 中的错误:'x' 和 'y' 长度不同。
正如我所说,这段代码适用于具有类似特征的其他数据集,所以我不确定问题是什么。