条形图后面的情节线 [英] plot line behind barplot

查看:45
本文介绍了条形图后面的情节线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个条形图,其中条形图绘制在水平线的顶部.

I would like to create a barplot where the bars are plotted on top of the horizontal line.

以下代码实现了这一点:

The following code accomplishes this:

y <- c(1,2,3,5)
barplot(y)
abline(h=mean(y))
barplot(y, add=T)

但是,我担心 barplot() 中的 add=T 参数,如果重复使用,会引入打印伪影.我很好奇是否有上述代码的替代方法(尽管上述代码可能是最快的方法).

However, I'm concerned that the add=T parameter in barplot(), if used repeatedly, can introduce printing artifacts. I'm curious if there's an alternative to the above code (though the above code may be the fastest method).

推荐答案

你可以在第一次调用时什么都不做:

You could just plot nothing in your first call:

y <- c(1,2,3,5)
barplot(rep(NA,length(y)),ylim=c(min(0,y),max(y)),axes=FALSE)
abline(h=mean(y))
barplot(y, add=T)

这篇关于条形图后面的情节线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆