How to change y axis max in time series using R

0 votes

I'm unable to set a customized y-axis range for time series plot since ts() object does not let you use ylim. If I use ylim, I get an unused variable error. Below is the code for my time series plot.

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

I am trying to add a horizontal line to time series graph using the abline function. But, y axis isn't large enough for the line to actually show. So, i'm wondering if there is any other way to extend y-axis.

Apr 3, 2018 in Data Analytics by nirvana
• 3,150 points
1,746 views

1 answer to this question.

0 votes

The axis limits are being set using the plot.ts(). So if you want to override the data, you can either set in there or before the par() function.

Though plotting behavior can be unexpected. below are the two options you can try:

Option ( 1 ) :

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

Option ( 2 ) :

TimeSeriesData <- ts(new$Value, start = c(input$years[1]), end = input$years[2])
par(ylim = c(<your min>, <your max>)
plot.ts(TimeSeriesData)
abline(h=amount$toxicityLevels, col="blue") 
answered Apr 3, 2018 by Sahiti
• 6,380 points

Related Questions In Data Analytics

+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,670 points
27,705 views
0 votes
1 answer
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 5, 2019 in Data Analytics by anonymous
10,655 views
+1 vote
1 answer

How to change fill color in each facet using ggplot2?

You can map the facetting variable to ...READ MORE

answered May 8, 2018 in Data Analytics by kappa3010
• 2,090 points
17,327 views
0 votes
1 answer

How to replace NA with 0 using starts_with()

Well I could suggest various options such ...READ MORE

answered Apr 3, 2018 in Data Analytics by Sahiti
• 6,380 points
583 views
0 votes
5 answers

How to remove NA values with dplyr::filter()

Hi, The dplyr has ’filter()’ function to do such filtering, ...READ MORE

answered Dec 10, 2020 in Data Analytics by MD
• 95,300 points
151,139 views
0 votes
1 answer
0 votes
1 answer

How can I use parallel so that it preserves the list of data frames

You can use pmap as follows: nc <- ...READ MORE

answered Apr 4, 2018 in Data Analytics by kappa3010
• 2,090 points
207 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 13, 2018 in Data Analytics by Sahiti
• 6,380 points
3,024 views
0 votes
2 answers

How to count unique values in R?

You can try this way, as.data.frame(v) %>% count(v) READ MORE

answered Aug 8, 2019 in Data Analytics by anonymous
5,416 views