# Why is the acf not ploted for large lags?

Hi all,

I use the forecasting package and I want to plot the acf of a time series. Strangely the acf is only calculated until a certain lag (about 35) and afterwards is not displayed anymore altough there is in fact autorcorrelation also for larger lags. Here you can see the data and the acf plot in a screenshot

Here you see the R code:

L <- acf(generationData$Price, plot = FALSE) plot(L, xaxt = 'no', xlim = c(1,50)) axis(1, at = c(1,5,10,50,75,125), xlim = c(1,200)) Can you tell me what the problem is? This also happens when using other time series data. The acf is not plotted for larger lags. I'd appreciate every comment. Use the lag.max argument to return a larger number of lags. For example, if you run L <- acf(generationData$Price, plot = FALSE, lag.max=100) do you get 100 lags?

Based on the help file for the acf function, the default for lag.max is 10*log_{10}(\frac{N}{m}), where N is the number of observations and m is the number of series (1 in this case). Based on your first graph, it looks like you have about 9,000 observations, which gives a default lag.max of 39.

Also, the xlim argument is needed only in the plot function. It doesn't do anything when added to axis.

1 Like

Are you using RStudio? I would suggest installing RStudio and creating an RStudio Project. Then you can open an R script, type your code there and save it as a file.

To use a custom title for a plot: plot(generationData$Price, xaxt = 'no', xlim = c(1,50), main="My Title"). You could also do: plot(generationData$Price, xaxt="n", main=NA)
title("My Title")


The acf plot uses R's "base" graphics system. ggtitle is from the ggplot2 package, which is a completely separate plotting system that uses R's "grid" graphics system and also has its own functions and grammar.

It might be helpful to check out the free book R for Data Science to learn more about how to analyze and visualize data with R (as well as the workflow of setting up R scripts and projects), and the free book Forecasting: Principals and Practice, 3rd ed. to learn more about forecasting with R.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thanks a lot joels for your great help. It solved my problem and I really appreciate your effort.

Just another side question: Is there a way how to save the console in R Studio. I know that R Studio has a history panel but I do not like this at all. I would rather prefer saving the code from the console.
And do you know how I can change the title of the plot. At the moment the title is "Series generationData\$Price" which I did not explicity specify before. I tried adding title ("Test") (from https://www.geeksforgeeks.org/add-titles-to-a-graph-in-r-programming-title-function/) but the inital title does not disappear and when using `
ggtitle("Plot of length \n by dose") from http://www.sthda.com/english/wiki/ggplot2-title-main-axis-and-legend-titles
I get an error message

I'd appreciate any further comments from you.

Thanks a lot.

Thanks for your answer and effort joels. Now the diagramm looks good due to your great help

Yes i am using RStudio (otherwise I would not use this forum :-)) and I did as you said. Basically the saving workes fine but there is a problem with the plot. Whenever I run the scipt the old plot is not deleted and the script just adds the new plot onto the old plot. How can I clear the plot?