[R] Plot.date and legends
Petr Pikal
petr.pikal at precheza.cz
Fri Mar 10 16:05:30 CET 2006
Hi
Why plot.date? I wonder if plot() did not work too.
Did not you get error with as.date? Probably as.Date was intended and
formating forgotten.
Legend requires some positioning from user's side and you can use
either
legend(xposition, yposition, legend="whatever you want to put here",
....)
where xposition and yposition are usually numeric values
see also ?xy.coords
or
legend("text of position", legend="whatever you want to put here",
....)
where text of position is one of texts mentioned in error you have
got.
from help page
...
The location may also be specified by setting x to a single keyword
from the list "bottomright", "bottom", "bottomleft", "left",
"topleft", "top", "topright", "right" and "center". This places the
legend on the inside of the plot frame at the given location. Partial
argument matching is used. The optional inset argument specifies how
far the legend is inset from the plot margins. If a single value is
given, it is used for both margins; if two values are given, the
first is used for x- distance, the second for y-distance.
...
HTH
Petr
On 10 Mar 2006 at 9:29, Bryan Sykes wrote:
Date sent: Fri, 10 Mar 2006 09:29:49 -0500
From: "Bryan Sykes" <BSykes at NBME.org>
To: <r-help at stat.math.ethz.ch>
Subject: [R] Plot.date and legends
> 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
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list