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,060 points
55 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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 darklord
• 6,140 points

Related Questions In Data Analytics

0 votes
1 answer

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$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
55 views
0 votes
1 answer
0 votes
1 answer

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

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 1,887 views
0 votes
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,010 points
1,714 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 darklord
• 6,140 points
33 views
0 votes
3 answers

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

Null values have no notion of equality ...READ MORE

answered Apr 11 in Data Analytics by Zane
3,338 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,010 points
20 views
0 votes
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 darklord
• 6,140 points
67 views
0 votes
1 answer

How to count unique values in R?

You can get the information printed in ...READ MORE

answered Apr 9, 2018 in Data Analytics by darklord
• 6,140 points
783 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.