0

I am making many line charts and I need the y axis to start at 0, but I want the max to be the max of the data, or whatever it needs to be to fit the data. I have this code:

ggplot(MonthView1, aes(x=as.factor(MONTH), y=Count,colour=as.factor(YEAR))) + 
geom_line(aes(group=as.factor(YEAR))) + geom_line(data=Statistics1, 
aes(y=Avg, group=1),color="Black",size=0.75)+xlab("Month")+ggtitle("Count of 
Reported Non-Weather Claims, Excluding No 
Pays")+scale_color_manual(values=c("red3", "orange3", "yellow4", "Green2" , 
"lightseagreen","darkgreen", "skyblue3", "midnightblue", "darkorchid4", 
"maroon4", "hotpink2" ))+theme(axis.text.y=element_text(size=12),axis.text.x=element_text(size=12))+scale_x_discrete(expand = c(0, 0))+scale_y_continuous(limits = c(0,200),expand = c(0, 0))+labs(color="Year")

The

scale_y_continous(limits = c(0,200)

works, but I do not want to keep changing the max value when the data changes. Also, I am using two dataframes for this graph, so how do I make it the max of all data, not just one dataframe? Thank you.

Reagan
  • 49
  • 1
  • 5
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. That will make it easier to help you. – MrFlick Jul 25 '18 at 17:46

1 Answers1

1

You can use NA to get the "default" value in the limits= parameter

ggplot(data.frame(x=1:10, y=11:20), aes(x,y)) + 
  geom_point()  + 
  scale_y_continuous(limits=c(0, NA))
MrFlick
  • 195,160
  • 17
  • 277
  • 295