Search code examples
rggplot2geom-bar

geom_col does not plot all data points


I have faced a weird behaviour of geom_col and it drives me crazy: basically it does not plot all the data points. When I add geom_point() I clearly see that they are not all represented with a bar.

MWE :

x = sample(1:2000, size = 600, replace = FALSE)
y = 1:600
ggplot(data.frame(x = x, y = y), aes(x,y)) + geom_col() + geom_point()

enter image description here


Solution

  • It is actually plotting all vertical lines, the problem is that it is too thin to show. If you zoom in you will see all the lines.

    Try to make the width of the lines thicker, e.g.

    ggplot(data.frame(x = x, y = y), aes(x, y)) + geom_col(width = 3) + geom_point()
    

    enter image description here