[R] Strange labels on plot with dates
Henrik Andersson
han at dmi.dk
Tue Apr 3 15:57:31 CEST 2007
Hmm,
I'm running 2.4.0 under linux
> sessionInfo()
R version 2.4.0 (2006-10-03)
i686-pc-linux-gnu
locale:
C
attached base packages:
[1] "methods" "stats" "graphics" "grDevices" "utils" "datasets"
[7] "base"
>
++++++++++++++++++++++
pdf("strange.pdf")
startdate <- strptime("2002-01-01",format="%Y-%m-%d")
enddate <- strptime("2006-12-31",format="%Y-%m-%d")
##enddate <- strptime("2002-12-31",format="%Y-%m-%d")
dates <- seq(startdate,enddate,by="week")
daynr <- as.numeric(julian(dates,origin=dates[1]))
yvar <- sin(daynr*2*pi/365)
plot(yvar~dates,type='l')
dev.off()
- Henrik
Gabor Grothendieck wrote:
> What version of R are you using? When I copy and paste that into
> R 2.4.1 on Windows XP I get 2001, 2002, ..., 2007
>
> On 4/3/07, Henrik Andersson <han at dmi.dk> wrote:
>> Hello fellow R people,
>>
>> I don't understand the default behavior of the axis labeling when
>> plotting dates.
>>
>> I would expect something like 2001, 2002 or possibly Jan 01, Jan
>> 02...Jan 06, but instead I only see Jan 01, Jan 01, Jan 01....
>>
>>
>> See the following example
>>
>> startdate <- strptime("2001-01-01",format="%Y-%m-%d")
>> enddate <- strptime("2006-12-31",format="%Y-%m-%d")
>> dates <- seq(startdate,enddate,by="month")
>>
>> daynr <- as.numeric(julian(dates,origin=dates[1]))
>>
>> yvar <- sin(daynr*2*pi/365)
>>
>> plot(yvar~dates,type='l')
>>
>> Cheers, Henrik
>>
>> --
>> Henrik Andersson
>>
>> Danish Meteorological Institute
>> Lyngbyvej 100
>> 2100 Copenhagen Ø
>> Denmark
>> Tel: +45 39157215
>> Email: han at dmi.dk
>>
>> ______________________________________________
>> 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.
>>
--
Henrik Andersson
Danish Meteorological Institute
Lyngbyvej 100
2100 Copenhagen Ø
Denmark
Tel: +45 39157215
Email: han at dmi.dk
-------------- next part --------------
A non-text attachment was scrubbed...
Name: strange.pdf
Type: application/pdf
Size: 6924 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-help/attachments/20070403/b0696add/attachment.pdf
More information about the R-help
mailing list