[R] use date as x-axis

Gabor Grothendieck ggrothendieck at gmail.com
Thu Oct 19 04:22:28 CEST 2006


Make sure that the Date column is actually of class "Date":

DF$Date <- as.Date(DF$Date, "%d-%b-%y")
plot(DF)

See ?as.Date .  Also read the Help Desk article in R News 4/1 to
learn more about dates.

On 10/18/06, tom soyer <tom.soyer at gmail.com> wrote:
> Hi,
>
> I have the following data in two columns. The first column is the date, the
> second is data.
>
> Date Data
> 3-Jan-95 459.21
> 4-Jan-95 459.13
> 5-Jan-95 460.73
> 6-Jan-95 460.38
> 9-Jan-95 460.67
> 10-Jan-95 460.9
> 11-Jan-95 461.68
> 12-Jan-95 461.64
> 13-Jan-95 461.64
> 16-Jan-95 465.97
> 17-Jan-95 469.38
> 18-Jan-95 470.05
> 19-Jan-95 469.72
> 20-Jan-95 466.95
> 23-Jan-95 464.78
> 24-Jan-95 465.81
> 25-Jan-95 465.86
>
> I would like to used the date as the x-axis and data the y-axis. I tried
> plot(Data~Date,data=d), where d is the R data frame variable that holds the
> two columns. But something very strange happened, although the graph has
> dates on the x-axis, the order of these dates are wrong. I searched the help
> file, and realized that I need to tell R explicitly to set the date as
> x-axis. Unfortunately, this is as far as I got, and I couldn't figure out
> exactly how to do this. Could someone please provide me with an example?
>
> Thanks,
>
> Tom
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>



More information about the R-help mailing list