[R] Plot.date and legends

Gabor Grothendieck ggrothendieck at gmail.com
Fri Mar 10 15:49:31 CET 2006


The argument to legend should be of class "date", not "character".
Also please post reproducible code including definitions of all
variables used and library calls.

On 3/10/06, Bryan Sykes <BSykes at nbme.org> wrote:
> Hi:
>
> I'm trying to plot dates on the x-axis of a code, but the legend is not being
> displayed.  I receive the following error:
>
> Error in match.arg(x, c("bottomright", "bottom", "bottomleft", "left",  :
>        'arg' should be one of bottomright, bottom, bottomleft, left,
> topleft, top, topright, right, center
> In addition: Warning message:
> longer object length
>        is not a multiple of shorter object length in: arg == choices
>
> The problem is that I have more than one trend line, and the legend doesn't
> seem to work given that the x-axis is a date.  I've searched prior help
> threads, but this issue hasn't come up.  Any ideas?  A sample code can be
> found below.
>
> date <-
> as.date(c("15-Jan-06","22-Jan-06","29-Jan-06","5-Feb-06","12-Feb-06","19-Feb-
> 06","26-Feb-06"))
>
> par(mfrow=c(2,1))
> plot.date (date, int_median, main="Median Time to Receive Outcome Files,
>           International and Domestic Centers Week", xlab="Week",
>           ylim=c(15,35), ylab="Median Hours", type = "l",lwd =1, lty=1)
> lines (date, dom_median, type = "l", lwd = 2, lty=2)
> abline(h=24, lwd=2)
> name <- c("International", "Domestic")
> legend (c("29Jan6","5Feb6"),c(26,35), name, lwd=c(1,2), lty=c(1,2))
>
> plot.date (date, int_mean, main="Mean Time to Receive Outcome Files,
>           International and Domestic Centers Week", xlab="Week",
>           ylim=c(15,35), ylab="Median Hours", type = "l",lwd =1, lty=1)lines
> (date, dom_mean, type = "l", lwd = 2, lty=2)
> abline(h=24, lwd=2)
>
>
> Thanks,
>
> Bryan L. Sykes
> Program Associate, Operations Research
> National Board of Medical Examiners
> bsykes at nbme.org
>
> ______________________________________________
> 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
>




More information about the R-help mailing list