[R] Plot.xts - how to change the x-axis labels to show weekly labels.

David Winsemius dwinsemius at comcast.net
Sun Jul 31 01:15:21 CEST 2011


On Jul 30, 2011, at 6:05 PM, Eduardo M. A. M.Mendes wrote:

> Hi Joshua
>
> Many thanks.
>
>> library(Hmisc);
>> plot.xts(x,major.ticks="weeks",major.format="%b/%d %H:%M:%S");
>> minor.tick(nx=7);
>
> The above  commands give me almost what I need. I just need to  
> figure out
> how to split the labels in two lines (without using ggplot2)

Use '\n' in your format string.

-- 
David
>
> Cheers
>
> Ed
>
>
>
> -----Original Message-----
> From: Joshua Ulrich [mailto:josh.m.ulrich at gmail.com]
> Sent: Saturday, July 30, 2011 1:09 PM
> To: Eduardo M. A. M.Mendes
> Cc: r-help at r-project.org
> Subject: Re: [R] Plot.xts - how to change the x-axis labels to show  
> weekly
> labels.
>
> Hi Eduardo,
>
> I'm not too familiar with plot.xts, but this answers 2/3 of your  
> requests.
> R> plot(x, major.ticks="weeks", major.format="%b %d")
>
> plot.zoo is quite a bit more flexible and has a lot of examples in
> ?plot.zoo.  Combining plot.zoo with endpoints should be able to give  
> you
> what you want.
>
> Best,
> --
> Joshua Ulrich  |  FOSS Trading: www.fosstrading.com
>
>
>
> On Sat, Jul 30, 2011 at 9:10 AM, Eduardo M. A. M.Mendes
> <emammendes at gmail.com> wrote:
>> Dear R-users
>>
>>
>>
>> I am new to R and struggling not to bother the list with silly  
>> questions.
>>
>>
>>
>> I read the documentation on xts and searched for some examples over
>> the internet on how to use plot.xts.
>>
>>
>>
>> The xts object is as follows
>>
>>
>>
>> dataxts : An 'xts' object from 2010-06-27 to 2010-08-05 containing:
>>
>>  Data: num [1:56161, 1:14] 74 74.2 74.2 74.1 73.9 ...
>>
>>  Indexed by objects of class: [POSIXct,POSIXt] TZ:
>>
>>  xts Attributes:
>>
>>  NULL
>>
>>
>>
>> The time index goes from 2010-06-27 to 2010-08-05 hourly, that is,
>> there are
>> 56151 time stamps.  If I issue plot.xts(dataxts[,1]) a graphics  
>> window
>> comes out with the following x labels:
>>
>>
>>
>> Jun 27 00:00, Jul 11 21:00, Jul 25 21:00, Aug 05  00:00
>>
>>
>>
>> I could not figure out how to change the number of ticks so that the
>> time stamps (major ticks) are shown weekly and the minor ticks daily.
>> Besides, I wonder whether the labels could be show as follows:
>>
>>
>>
>> Jun 27       Jul 11   Jul 25  Aug 05 (just as example)
>>
>> 00:00         21:00   21:00  00:00
>>
>>
>>
>> Thanks for your help and patience.
>>
>>
>>
>> Cheers
>>
>>
>>
>> Ed
>>
>>
>>
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list