2

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

3
  • geom_col(position = "identity") does not change anything Commented May 11, 2017 at 13:21
  • @Bankelal each point should have one associated bar. I have change the MWE so as to be more reproducible. I guess there is something with the range of x Commented May 11, 2017 at 13:47
  • This is not a problem with geom_col, but depends on you graphics device. Commented May 11, 2017 at 14:01

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

uhmm, it works, but I think this is a very misleading behaviour of geom_col. What if the sequence becomes arbitrarily longer? It means that one can never be sure one sees all the samples
I also found it strange at first but it makes sense, you can not see arbitrarily thin lines on your monitor. The default width is just too thin.
they could overlap like geom_point and geom_line for instance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.