在绘图中将平均值添加到y轴

时间:2016-02-29 11:55:48

标签: r plot graph statistics mean

我希望样本的平均值显示在我的y轴上。我尝试过这样做,就像他们在 this post中解释过一样,但它似乎没有用。如果你看image,红线代表平均值。我只需要在y轴上显示该值。任何帮助表示赞赏。

我的R代码:

xyear = seq(1920,1978,1)
plot(xyear,difference, type = "bar", col = "blue", main = "Difference between precipitation in winter and summer", xlab = "Year", ylab = "Difference")
abline(difference.mean, 0, col = "red")

谢谢!

1 个答案:

答案 0 :(得分:1)

/Users/username/
在这种情况下,

xyear = seq(1920,1978,1) plot(xyear,difference, type = "bar", col = "blue", main = "Difference between precipitation in winter and summer", xlab = "Year", ylab = "Difference") abline(mean(difference), 0, col = "red") axis(side = 2, at=mean(difference), labels=T) 命令应该有所帮助。有关详细信息,this page可能会有所帮助。