0

I am trying to produce a number of histograms, all with the same range for the x-values ranging from 0 to 1E6. For some histograms, however, there are a lot of zeros and the maximum number is only 400. So what I want is a histogram with just one large bar at the left edge.

If I use the option scale_x_continuous, somehow all the zeros are lost and I get an error message. Below an example with some simulated data, where the hist() command produces the correct and expected graph.

t = c(rep(0,1E4), rep(1,1E3), rep(2,1E2), 10, 20, 30)
dat = data.frame(t)
hist(t, xlim=c(0,1E6))
ggplot(dat, aes(x = t))  + geom_histogram()   +ylim(c(0,1E5))+ 
  scale_x_continuous(breaks=c(0,1E6), limits = c(0,1E6))

The error message I get is

stat_bin() using bins = 30. Pick better value with binwidth. Warning message: Removed 2 rows containing missing values (geom_bar).

4

0 回答 0