geom_bar bars not displaying when specifying ylim

后端 未结 3 1973
伪装坚强ぢ
伪装坚强ぢ 2020-11-29 05:15

I\'m having a problem with geom_bars wherein the bars are not rendered when I specify limits on the y-axis. I believe the following should reproduce the problem:

         


        
3条回答
  •  长情又很酷
    2020-11-29 05:44

    Adding an answer for my case which was slightly different in case someone comes across this:

    When using position="dodge", the bars get horizontally resized automatically to fill space that is often well beyond the limits of the data itself. As a result, even if both your x-axis and y-axis limits are limits=c(min-1, max+1, for certain data sets, the position="dodge" might resize it beyond that limit range, causing the bars to not appear. This might even occur if your limit floor is 0, unlike the case above.

    Using oob=rescale_none in both scale_y_continous() AND scale_x_continuous() fixes this issue by simply cutting off the resizing done by position="dodge".

    As per earlier comment, it requires package:scales so run library(scales) first.

    Hope this helps someone else where the above answers only get you part way.

提交回复
热议问题