[R] matplot with dates/times on horizontal axis

Jim Lemon jim at bitwrit.com.au
Wed Jul 13 11:47:12 CEST 2011


On 07/12/2011 10:48 PM, Alex van der Spek wrote:
>  >matplot(timestamp,xymatrix,type='l')
>
> where timestamp is a vector filled with POSIXct objects and xymatrix is
> a numeric 2x2 matrix plots but the horizontal axis labels are raw
> unformatted timestamps.
>
> I would like to format these in any of the available codes for strftime,
> for instance format="%H:%M".
>
> Passing a vector of formatted strings does not work. Any obvious other
> ways fail upon me as well.
>
> Any ideas to make this work?

Hi Alex,
I would use the "xaxt" argument to matplot and then add the axis:

matplot(...,xaxt="n")
timelabels<-format(timestamp,"%H:%M")
axis(1,at=timestamp,labels=timelabels)

Jim



More information about the R-help mailing list