R:在小节中点未居中吧台 [英] R: in barplot midpoints are not centered w.r.t. bars

查看:75
本文介绍了R:在小节中点未居中吧台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在R中使用barplot注意到了一些奇怪的事情.让y为向量

I have just noticed something strange using barplot in R. Let y be the vector

> y
[1] 24924006 15310556 11638412  9542834  8696133

使用y上的barplot到达中点矢量

bp <- barplot(y)

同时绘制柱线和中点我注意到柱线没有居中.中点...这很奇怪;总之,我使用

Plotting both bars and midpoints I notice that the bars are not centered .w.r.t. the midpoints...and this is odd; in summary, I use

bp <- barplot(y)
points(bp)

使用

作为结果.你能帮我解决这个小难题吗?我只会有中间点居中的酒吧.谢谢!

as outcome. Could you please help me solving this little puzzle? I would just have bars with centered mid-points. Thanks!

推荐答案

如果将barplot()结果保存为对象,则会得到条形的中点.

If you save the barplot() result as an object you get the midpoints for the bars.

bp <- barplot(y)
bp
     [,1]
[1,]  0.7
[2,]  1.9
[3,]  3.1
[4,]  4.3
[5,]  5.5

如果现在在其他绘图功能中使用它们,则这些中点应为x值.在呼叫plot(bp)中,它们用作y值,而x值是序列号1,2,3,4,5-因此它们不对应于中点.

If you use them now in other plotting functions those midpoints should be as x values. In call plot(bp) they are used as y values and x values are sequence numbers 1,2,3,4,5 - so they do not correspond to midpoints.

还提供y值,按预期绘制点.

Providing also y values, points are plotted as expected.

bp <- barplot(y)
points(bp,c(10,20,30,40,50))

这篇关于R:在小节中点未居中吧台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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