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
125 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 darklord
• 6,170 points

Related Questions In Data Analytics

0 votes
2 answers
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 in Data Analytics by anonymous
3,135 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,020 points
2,879 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,170 points
50 views
0 votes
4 answers

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

Can we create a alist as below ...READ MORE

answered Aug 5 in Data Analytics by anonymous
7,595 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,020 points
37 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 darklord
• 6,170 points
169 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 in Data Analytics by anonymous
1,510 views