0

I am trying to plot data in a line graph / scatter plot. However, large error bars are causing the y-axis to have negative values which are unnecessary. How do I get the y-axis to stop at 0? Thanks!

ggplot(Chromhabsum, aes(x=Year,y=meanhab, group=Habitat, colour=Habitat, shape=Habitat))+
  geom_point(position=position_dodge(width=0.35))+
  geom_errorbar(aes(ymin=meanhab-(sehab*1.959964), ymax=meanhab+(sehab*1.959964)), position=position_dodge(width=0.35), width=0.3)+
  labs(y=y_hab_title, x="Year")+
  scale_x_continuous(breaks=c(2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018))+
  scale_y_continuous(breaks=c(0, 10, 20, 30))+ 
  geom_line()+
  theme_bw()

enter image description here

Roman
  • 17,008
  • 3
  • 36
  • 49
Tom
  • 1
  • Hmmm...instead of cropping you actual data, re evaluate your theory e.g. collect more samples. But you can fix it with limits. check `?scale_y_continuous` for that parameter. Try the median and quartiles instead of the mean? – Roman May 08 '20 at 08:47
  • 1
    I tend to use `coord_cartesian` which has some important differences with `scale_y_continuous`. This is discussed in [How to set limits for axes in ggplot2 R plots?](https://stackoverflow.com/questions/3606697/how-to-set-limits-for-axes-in-ggplot2-r-plots). – KevinJWalters May 08 '20 at 09:50

0 Answers0