0

I am trying to build a 24 hours long time interval, by scale_x_continuous:

ggplot() + 
scale_x_continuous(breaks = seq(0, 24, by = 1)) +
geom_histogram(aes(x=df$h1), fill="red", color="red", alpha = 0.4, bins = 23) + 
geom_histogram(aes(x=df$h2), fill="blue", color="blue", alpha = 0.4, bins=23) 

but, so doing, I get the entire interval (0-24) concentrated on the first histogram's bin. Why?

Simone
  • 4,800
  • 12
  • 30
  • 46
  • Could it be because your number of bins (23) is not consistent with the scale? (Should there not be 25 bins?). This might be a very silly comment. It is hard to see what is happening without data nor the graph. I just wonder if R, unable to match the scale and the bins with a one for one is putting all the bins in one scale unit as the only way to make it work. – prosoitos Oct 21 '18 at 20:20
  • Can you please give an example of what's in df$h1, eg with `dput(head(df))`? – Jon Spring Oct 21 '18 at 22:16
  • 3
    Hard to say without a [reproducible question](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), but I see 2 things happening that you could learn about from any `ggplot2` tutorial: you never want to [use `$` inside `aes`](https://stackoverflow.com/q/32543340/5325862), and you generally want to [use long-shaped data](https://stackoverflow.com/a/3777592/5325862) to assign variables to aesthetics – camille Oct 21 '18 at 23:42
  • @JonSpring I can't show here the result of `dput(head(df))`, because `df` has more than 100 features. – Simone Oct 22 '18 at 00:44
  • Then perhaps `dput(head(df$X2014))`? That's the thing you're binning but we don't know what kind of data it is. – Jon Spring Oct 22 '18 at 01:32

0 Answers0