R: in barplot midpoints are not centered w.r.t. bars

后端 未结 1 1101
日久生厌
日久生厌 2020-12-11 03:56

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

> y
[1] 24924006 15310556 11638412  9542834  8696133

相关标签:
1条回答
  • 2020-12-11 04:44

    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
    

    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.

    Providing also y values, points are plotted as expected.

    bp <- barplot(y)
    points(bp,c(10,20,30,40,50))
    
    0 讨论(0)
提交回复
热议问题