On Aug 31, 2011, at 12:06 PM, Peter Maclean wrote:
> Hi:
> Trying for hours to add a legend to a periodogram. Any help will be
> appreciated.
> For example, how can I add a legent (showing x1, x2, x3, x4) to both
> plots (generated by spec.program() and plot()? Here is a worked
> example.
>
> require(TSA)
> require(graphics)
> require(stats)
> t<-1986:2011
> x1<-cos(t*1990/2011)
> x2<-cos(t*2000/20011)
> x3<-sin(t*1990/2011)
> x4<-sin(t*2000/2011)
> y<-cbind(t,x1,x2, x3,x4)
> y.time = ts(y.time, start=1986, frequency=1)
> y.spc<-spec.pgram(y.time, spans = c(3,3),
> detrend=FALSE,log="no",plot = TRUE,
kernel("modified.daniell",
> c(5,7)))
> plot(y.spc, plot.type = "marginal", main="Smoothed
Periodogram")
The code throws an error. Perhaps you meant:
> y.time = ts(y[ ,"t"], start=1986, frequency=1)
At any rate the answer to the question is probably:
class(y.spc) # class "spec"
?methods(plot) # the spec method is not hidden
plot.spec # uses base graphics ..... so
?legend
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT