helloworld
helloworld

Reputation: 181

Changing y axis max in time series R

The ts() object in R doesn't seem to let you use ylim so I'm unable to set a customized y axis range for my time series. If i do use ylim i get a unused variable error. This is what i have for plotting my time series:

dataTimeSeries <- ts(newru$Value, start = c(input$years[1]), end = input$years[2])
plot.ts(dataTimeSeries)
abline(h=amount$toxicityLevels, col="blue")   #add horizontal line

I'm trying to add a horizontal line to the time series graph via the abline function, but sometimes the y axis isn't large enough for the line to actually show which is why I'm wondering if theres another way to extend the y axis. Thanks!

Upvotes: 1

Views: 1281

Answers (1)

De Novo
De Novo

Reputation: 7610

Your axis limits are being set in the plot.ts() call. If you want to override the data, set it there, or before there with par().

plotting behavior can be a little unexpected, though, so I can't guarantee it will work without a dput of your data, but here are two options for you to try:

dataTimeSeries <- ts(newru$Value, start = c(input$years[1]), end = input$years[2])
plot.ts(dataTimeSeries, ylim = c(<your min>, <your max>))
abline(h=amount$toxicityLevels, col="blue") 

Alternatively

dataTimeSeries <- ts(newru$Value, start = c(input$years[1]), end = input$years[2])
par(ylim = c(<your min>, <your max>)
plot.ts(dataTimeSeries)
abline(h=amount$toxicityLevels, col="blue") 

Upvotes: 1

Related Questions