[R] Beginner's question about plotting variables in a time series object with the date on the x axis
David Winsemius
dwinsemius at comcast.net
Tue Oct 18 02:09:01 CEST 2011
On Oct 17, 2011, at 5:23 PM, Iara Faria wrote:
> Dear R helpers,
>
> I am a beginner at R so please be gentle :)
> I have already read manuals and FAQs, with no help.
> I have a monthly time series data on public debt with 40 variables,
> it starts on January 1994 and ends on June 2011.
I agree with Weyland. Figuring out how to use class `ts` objects in R
is difficult. If it were easy I don't think Zeileis would have
invented `zoo`.
> I am loading the data into R using read.csv and the data looks ok
> when I do edit(dados):
>> dados<-read.csv("dadosR3.csv", header=T)
> then I tried making it into a time series object, using:
>> dados2<-ts(dados, start = c(1994,1), frequency=12)
(See below for what that did.)
>
> Now when I try plotting any of the variables, for example divliq.pib
> (net debt), the date doesn't appear on the x axis. How can I do this?
> I use
>> plot.ts(divliq.pib)
Try:
plot(time(dados2), dados[, "divliq.pib"] , xy.labels=FALSE))
>
> also the function names() doesn't work, which would be important
> since I have so many variables.
>> names(dados2)
Read the help page again(?). "A data frame will be coerced to a
numeric matrix via data.matrix."
The names function only works for lists and name vectors. Try colnames()
> NULL
>
> I am using R.2.13.1
>
> Thank you very much.
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
More information about the R-help
mailing list