Re: [R] Query: how to modify the plot of acf

From: Matthias Braeunig <>
Date: Sat 19 Aug 2006 - 04:56:36 EST

Hi Stefano,

the manual tells us that we can access components of an acf object directly by acf.obj[.], but assignment ]<- does not work this way.

One way of doing what you want is to assign NA to x$acf[x$lag==0] like so:

x <- acf(runif(100))
x$acf[1] <- NA

But I suppose what you actually want is to have a reasonable ylim to be in effect when plotting your acf. I have struggled with this myself and found the following solution:

In plot.acf the formula for the white noise confidence interval is something along the lines of

acf.clim <- function(x=stop("your acf"), n=x$n.used, CL=.95) {

        cl = qnorm((1+CL)/2)/sqrt(n)
        attr(cl,"CL") <- CL
        return( cl)


Using this function you can plot
x <- acf(runif(100),plot=F)
plot(x, ylim=2*acf.clim(x)*c(-1,1)) # adjust magnification as needed

As for your second question we first prevent plotting of x-axis and then add our custom axis:

x <- acf(runif(1000),100,plot=F)
plot(x, ylim=2*acf.clim(x)*c(-1,1),xaxt='n') # note option 'xaxt'! axis(1,at=12*(0:8))

Hope that helps,


NB: It would be a good idea to include the acf.clim(.) inside of the acf object... Now it is somewhat hidden inside of plot.acf

x$clim <- acf.clim(x)

Stefano Sofia wrote:
> I need to modify the graph of the autocorrelation. I tried to do it through plot.acf but with no success.
> 1. I would like to get rid of the lag zero
> 2. I would like to have numbers on the x-axis only at lags 12, 24, 36, 48, 60, ...
> Could anybody help me in this?
> Any help will be appreciated
> Thank you for your attention
> Stefano
> [[alternative HTML version deleted]]
> ______________________________________________
> mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.

Journalist: "Mr. Gandhi, what do you think of Western civilization?"
Gandhi: "I think it would be a good idea."

~                   Matthias Braeunig, Dipl.Phys.
~                University Medical Center Freiburg
~    Institute of Environmental Medicine and Hospital Epidemiology
~     Department of Evaluation Research in Complementary Medicine
~          Hugstetter Str. 55, D - 79106 Freiburg, Germany
~              Phone: +49 (0)761 270-8306, Fax: -8343
~             Web:
~           Email:

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Sat Aug 19 05:02:29 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 19 Aug 2006 - 06:21:43 EST.

Mailing list information is available at Please read the posting guide before posting to the list.