[R-SIG-Finance] two zoo questions

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 9 13:12:19 CEST 2008


1. I can't reproduce your description either. When
I run the following using zoo 1.5-3 and  "R version 2.7.0 RC
(2008-04-17 r45367)"
the labelling on the X axis is May 22, May 27, Jun 01, Jun 06, Jun 11 and Jun 16
and when in the second plot statement (###) we plot the first series
using ordinary,
not zoo, graphics we get the exact same X axis (as expected) so there is nothing
specific to zoo here -- that is how automatic labelling in R works.

Maybe your ShorterSpan object is not what you think.  Try posting
dput(ShorterSpan) or perhaps inspection will make it immediately clear.
(Continued after code.)

library(zoo)
Lines <- " PXreturns VaRWHSe099 VaRWHSe095
2006-05-19 -0.6479279   1.878092   1.515232
2006-05-22 -6.1249511   1.878092   1.515232
2006-05-23  2.3501118   1.878092   1.515232
2006-05-24 -4.2859466   2.350112   2.350112
2006-05-25  2.6466856   2.350112   2.350112
2006-05-26  2.5496719   2.646686   2.646686
2006-05-29 -0.7580990   2.646686   2.646686
2006-05-30 -1.9170851   2.646686   2.646686
2006-05-31 -1.8566689   2.646686   2.646686
2006-06-01  1.4198415   2.646686   2.646686
2006-06-02  1.6703232   2.646686   2.646686
2006-06-05 -0.4974407   2.646686   2.646686
2006-06-06 -1.6936396   2.646686   2.646686
2006-06-07 -3.0212406   2.646686   2.646686
2006-06-08 -4.0235989   2.646686   2.646686
2006-06-09 -1.3131054   2.646686   2.646686
2006-06-12 -2.4710858   2.646686   2.646686
2006-06-13 -3.0808024   2.646686   2.646686
2006-06-14  1.9859772   2.646686   2.646686
2006-06-15  7.0481958   2.646686   2.646686
2006-06-16  0.1095805   7.048196   7.048196
2006-06-19  2.4037947   3.583430   7.048196
"
ShorterSpan <- read.zoo(textConnection(Lines), skip = 1, FUN = as.Date)
colnames(ShorterSpan) <- read.table(textConnection(Lines), nrow = 1)

plot(ShorterSpan, plot.type = "single", type = "p", xlab = "Date", ylab = "",
   col = list("black", "red", "orange"), pch = c(19,22,23), las = 1)

# gives same X axis labelling -- does not use plot.zoo
plot(time(ShorterSpan), coredata(ShorterSpan)[,1]) ###


2. Regarding your second question, you can change the format as in the
previously posted response or by issuing a custom axis command:

plot(ShorterSpan, type = "p", screen = 1, xaxt = "n")
ax <- as.Date(axTicks(1))
axis(1, ax, format(ax, "%Y-%m-%d"), cex.axis = 0.7)



On Fri, May 9, 2008 at 4:18 AM, michal miklovic <mmiklovic at yahoo.com> wrote:
> Hi,
>
> I have a zoo object with three time series and the corresponding dates. When I plot it, the x-axis contains dates which are not in the object and, naturally, no data points are displayed for these dates. For example, the date "2006-05-20" is not in the object, but it appears in the x-axis of the plot. As a result, I get a plot with 'empty' segments. The object, my code and sessionInfo are copied below.
> I would like to ask if it is possible to plot only the relevant dates, i.e. to produce a plot without, e.g., the date "2006-05-20". If yes, how could I do it?
>
> My second question concerns the way of displaying the dates on the x-axis. Currently, the dates are displayed as "V 22", which stands for "2006-05-22". I would like them to be displayed as "22 05 2006" or "22 May 2006". How can I do this?
>
> Thanks for your help!
>
> Michal
>
>
> The zoo object, ShorterSpan:
>            PXreturns VaRWHSe099 VaRWHSe095
> 2006-05-19 -0.6479279   1.878092   1.515232
> 2006-05-22 -6.1249511   1.878092   1.515232
> 2006-05-23  2.3501118   1.878092   1.515232
> 2006-05-24 -4.2859466   2.350112   2.350112
> 2006-05-25  2.6466856   2.350112   2.350112
> 2006-05-26  2.5496719   2.646686   2.646686
> 2006-05-29 -0.7580990   2.646686   2.646686
> 2006-05-30 -1.9170851   2.646686   2.646686
> 2006-05-31 -1.8566689   2.646686   2.646686
> 2006-06-01  1.4198415   2.646686   2.646686
> 2006-06-02  1.6703232   2.646686   2.646686
> 2006-06-05 -0.4974407   2.646686   2.646686
> 2006-06-06 -1.6936396   2.646686   2.646686
> 2006-06-07 -3.0212406   2.646686   2.646686
> 2006-06-08 -4.0235989   2.646686   2.646686
> 2006-06-09 -1.3131054   2.646686   2.646686
> 2006-06-12 -2.4710858   2.646686   2.646686
> 2006-06-13 -3.0808024   2.646686   2.646686
> 2006-06-14  1.9859772   2.646686   2.646686
> 2006-06-15  7.0481958   2.646686   2.646686
> 2006-06-16  0.1095805   7.048196   7.048196
> 2006-06-19  2.4037947   3.583430   7.048196
>
> My code:
>
> plot(ShorterSpan, plot.type = "single", type = "p", xlab = "Date", ylab = "",
>    col = list("black", "red", "orange"), pch = c(19,22,23), las = 1)
> legend.text <- expression(paste("% log returns on PX"),
>    paste("VaR WHS, ", eta, " = 0.99"), paste("VaR WHS, ", eta, " = 0.95"))
> legend("topleft", legend.text, col=c("black", "red","orange"), pch = c(19,22,23),
>    bty="n", y.intersp = 1.5)
>
>
> sessionInfo()
>
> R version 2.6.2 (2008-02-08)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=Slovak_Slovakia.1250;LC_CTYPE=Slovak_Slovakia.1250;LC_MONETARY=Slovak_Slovakia.1250;
> LC_NUMERIC=C;LC_TIME=Slovak_Slovakia.1250
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] zoo_1.5-2
>
> loaded via a namespace (and not attached):
> [1] grid_2.6.2     lattice_0.17-6
>
>
>
>      ____________________________________________________________________________________
>
> [[elided Yahoo spam]]
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



More information about the R-SIG-Finance mailing list