[R] Displayed Date Format in Plot Title.

R. Michael Weylandt michael.weylandt at gmail.com
Fri Apr 13 21:14:46 CEST 2012


as.Date() attemps to coerce a character string to a date where you
specify the input format -- if you want to specify an output format,
you need ?strftime [str + f + time == string format time]

E.g.,

titleDate <- as.Date("2011-05-03", format = "%Y-%m-%d")

plot(1:10, main = strftime(titleDate, "%b-%d-%Y"))

Michael

On Fri, Apr 13, 2012 at 2:43 PM, Sam Albers <tonightsthenight at gmail.com> wrote:
> Hello all,
>
> I can't seem to figure out how to format a date as a title. I have
> something like this:
>
> plot(x=1:10, y=runif(10,1,18), main=paste(as.Date("2011-05-03",
> format="%Y-%m-%d")))
>
> ## When I would really like this
> plot(x=1:10, y=runif(10,1,18), main=paste("May-03-2011"))
>
> ## I thought to try this but that produces an NA.
> plot(x=1:10, y=runif(10,1,18), main=paste(as.Date("2011-05-03",
> format="%Y-%b-%d")))
>
> How do folks usually accomplish something like this?
>
> Thanks so much in advance!
>
> Sam
>
> ______________________________________________
> 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.



More information about the R-help mailing list