« Return to Thread: two zoo questions

Re: two zoo questions

by michal miklovic :: Rate this Message:

Reply to Author | View in Thread

Hi,

thanks for your prompt responses.
I am sorry for not being clear in my first question. The date "2006-05-20" was not displayed in my plot but the x-axis contained a corresponding 'slot' although the date is not in the zoo object. Similarly, the date "Jun 11" is displayed but there are no observation for this date.
I would like my x-axis to contain only the dates that are in the object. In other words, I do not want my plot to have empty segments, which arise from adding dates without observations to the x-axis. Is this possible?

Concerning my second question, your suggestions worked fine.

Thanks again for your help.

Best regards,

Michal


'dput' output:

structure(c(-0.647927859775788, -6.12495112247933, 2.35011183030576,
-4.28594659156438, 2.64668558870609, 2.54967191535274, -0.758099006348889,
-1.91708512600499, -1.85666892546967, 1.41984151778516, 1.67032322347964,
-0.49744067461619, -1.69363956562325, -3.02124058139697, -4.02359885185390,
-1.31310542630114, -2.47108579725168, -3.08080237199411, 1.98597717860372,
7.04819583250611, 0.10958047433407, 2.40379468330145, 1.87809239730186,
1.87809239730186, 1.87809239730186, 2.35011183030576, 2.35011183030576,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 7.04819583250611,
3.58343037136928, 1.51523152190878, 1.51523152190878, 1.51523152190878,
2.35011183030576, 2.35011183030576, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 2.64668558870609, 2.64668558870609, 2.64668558870609,
2.64668558870609, 7.04819583250611, 7.04819583250611), .Dim = c(22L,
3L), .Dimnames = list(NULL, c("PXreturns", "VaRWHSe099", "VaRWHSe095"
)), index = structure(c(13287, 13290, 13291, 13292, 13293, 13294,
13297, 13298, 13299, 13300, 13301, 13304, 13305, 13306, 13307,
13308, 13311, 13312, 13313, 13314, 13315, 13318), class = "Date"), class = "zoo")




----- Original Message ----
From: Gabor Grothendieck <ggrothendieck@...>
To: michal miklovic <mmiklovic@...>
Cc: r-sig-finance@...
Sent: Friday, May 9, 2008 1:12:19 PM
Subject: Re: [R-SIG-Finance] two zoo questions

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@...> 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@... mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



      ____________________________________________________________________________________

[[elided Yahoo spam]]
        [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance@... mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only.
-- If you want to post, subscribe first.

 « Return to Thread: two zoo questions