Re: [R] Simple Newbie Question

From: Gabor Grothendieck <>
Date: Thu, 21 Feb 2008 19:03:51 -0500

On Thu, Feb 21, 2008 at 4:51 PM, MassimoH <> wrote:
> How do I plot data like this:
> Date,Series,Value
> 1/5/2007,Blue,300
> 1/20/2007,Blue,400
> 1/9/2007,Red,200
> 1/15/2007,Red,500
> Two things I'm having trouble figuring out from online help & tutorials:
> 1) How does R handle dates? It seems there is no built-in support for dates,

> but some standard add-ons provide date functionality? I can also convert my
> dates to number of days, however I'd like my plots to show date values on
> the x-axis.

See ?axis.Date for examles of plotting with dates. See R News 4/1 for more on dates. If you are working with time series see the zoo package.

> 2) How do plots support multiple "series" of data? Using R terms, the Series
> is a "factor" type. I want each series to be plotted with a different color.

Lines <- "Date,Series,Value


DF <- read.csv(textConnection(Lines))
DF$Date <- as.Date(DF$Date, "%m/%d/%Y")

# assuming Series contains valid R colors: plot(Value ~ Date, DF, type = "n")
for (x in levels(DF$Series)) lines(Value ~ Date, DF, subset = Series == x, col = x, type = "o") mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Fri 22 Feb 2008 - 00:08:36 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 22 Feb 2008 - 00:30:16 GMT.

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

list of date sections of archive