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

From: Matthias Braeunig <mb.atelier_at_web.de>
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 <- NA
plot(x)

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,

Matthias

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)
str(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]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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: http://kompmed.uniklinik-freiburg.de
~           Email: matthias.braeunig@uniklinik-freiburg.de
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help