[R] Plot with x-axis dates

Gabor Grothendieck ggrothendieck at gmail.com
Sat Feb 7 13:45:35 CET 2009


On Sat, Feb 7, 2009 at 6:10 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> On 06/02/2009 4:48 PM, Paul Warren Simonin wrote:
>>
>> Hello,
>>   I am attempting to create plots using two continuous variables and  it
>> seems I should be able to use the simple "plot" command. However,  my x-axis
>> values are dates, and I believe this could be the reason I  am receiving
>> error messages reading:
>>
>> Error in Summary.factor(c(2L, 4L, 3L, 5L, 6L, 7L, 1L), na.rm = FALSE) :
>>   range not meaningful for factors
>>
>> I have attempted to convert the date values to official dates within R
>>  and have done that successfully using the as.date function, but this  did
>> not help in the plots. So, how can one create plots in which the  x-axis is
>> date values? I know it would be possible to convert all my  dates into a
>> different linear scale (e.g., julian dates). However, I  would like to
>> complete this process as simply as possible.
>
> You can do plots using dates on the axis, e.g.
>
> dates <- ISOdate(2009, 1:12, 1) # first of every month
> plot(dates, 1:12)

I would be a bit careful here since there could be some
misalignment due to GMT vs. current time zone depending
on what you have.   See R News 4/1 for more.




More information about the R-help mailing list