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,130 points
3,831 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,370 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,700 points
35,823 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 6, 2019 in Data Analytics by anonymous
14,090 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
25,444 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,370 points
1,657 views
+1 vote
5 answers

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

Try this: df %>% filter(!is.na(col1)) READ MORE

answered Mar 26, 2019 in Data Analytics by anonymous
331,374 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
1,070 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 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,037 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
6,599 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP