0

Using scale_x_continuous with geom_histogram always results in a false error regarding rows removed.

I believe this may be because a histogram is technically on a discrete axis, but the reason for the error still doesn't make sense. scale_x_discrete does not produce the error, but does not manipulate the axis as easily either.

group<-rep(1:2,500)
df<-data.frame(group)
df$length<-group*0.75*(sample(200:800,1000,replace = T))

min(df$length)
max(df$length)

histogram <- ggplot(df, aes(x=length, fill = as.factor(group))) +
  geom_histogram (aes(y=..count..), position = "identity", alpha = 0.6, binwidth = 10, colour="black") + 
  scale_y_continuous(limits=c(0,25),expand=c(0,0),breaks=c(0,25,5))+
  scale_x_continuous (limits = c(100,1300),expand = c(0,0),breaks=seq(100,1300,100)) +
  scale_fill_discrete () +
  ylab("Count") + xlab("Length");histogram
Tanner33
  • 120
  • 2
  • 15
  • 2
    I'm not sure this should be closed. At any rate, removing the `limits` and `expand` arguments from `scale_x_continuous` and adding `+ coord_cartesian(xlim = c(0, 1500))` altered the plot size to 0-1500 without any errors. – cardinal40 Jan 08 '20 at 22:01
  • Thank you. This is helpful. Unfortunately, I think my question was considered a duplicate more because of the title than the question itself. – Tanner33 Jan 09 '20 at 22:06

0 Answers0