[R] Antwort: Re: legend with filled boxes AND lines

florian.koller at gfk.com florian.koller at gfk.com
Mon Jul 3 19:23:14 CEST 2006


Hi Martin,

I know about the merge command, but I want a line without the box in the
legend. Ideally I would need some argument that tells the fill subcommand
not only to suppress the box color (see example below), but also to
suppress the frame of the fill box. Alternatively if someone could tell me
how to modify the color of the frame, this would help, too, because I could
simply set it to the bg command.


x1 <- rnorm(100)
x2 <- rnorm(100, 2)
hist(x1, main = "", col = "orange",ylab = "density", xlab = "x", freq = F,
density = 55,
     xlim = c(-2, 5), ylim = c(0, 0.5))
par(new = T)
hist(x2, main = "", col = "green", ylab = "", xlab = "",axes = F,
xlim = c(-2, 5), ylim = c(0, 0.5), density = 45, freq = F)
abline(v = mean(x1), col = "orange", lty = 2, lwd = 2.5)
abline(v = mean(x2), col = "green", lty = 2, lwd = 2.5)
legend(3, 0.45, legend = c("x1", "x2", "mean(x1)", "mean(x2)"),
       col = c("orange", "green"), fill=c("orange","green", 0, 0),
       lty = c(0, 0, 2, 2), merge = T)


Thank you,
Florian Koller


Martin Maechler <maechler at stat.math.ethz.ch> schrieb am 03/07/2006
18:41:54:

> Did you try  legend(......, lty=..., fill=...,  merge = TRUE) ?
>
> In an example I just tried, this allowed to give filled boxes
> *and* lines.
>
> Please give a reproducible example of what you did -- maybe by
> modifying one of the many  example(legend)  examples.
>
> Martin Maechler, ETH Zurich
>
> >>>>> "florian" == florian koller <florian.koller at gfk.com>
> >>>>>     on Mon, 3 Jul 2006 13:40:33 +0200 writes:
>
>     florian> Dear all,
>
>     florian> Is there a straightforward way to create a legend
>     florian> box that has both filled boxes and lines?  So far I
>     florian> have built around this problem by creating two
>     florian> legends (with bty = "n") and manually drawing a box
>     florian> around both (but this is cumbersome, because I have
>     florian> to check upon the y coordinates of the legends
>     florian> every time).
>
>     florian> If I do something like > legend( ...,c("X1","X2",
>     florian> "mean"), fill = c("red", "blue", 0), lty = (0,0,2))
>     florian> < , I cannot get rid of the unfilled box or change
>     florian> the color of the fill box border (from its default
>     florian> color "black"), and I end up with two filled boxes
>     florian> and an empty, black-lined box plus the line as a
>     florian> legend for the third argument "mean". This trick
>     florian> therefore only works if I define "black" as the bg
>     florian> color for the complete legend box (because it masks
>     florian> the empty box from the fill argument). So, if there
>     florian> is a command to modify the color of the fill box
>     florian> border line (not the legend box border line), this
>     florian> would help me, too (still not ideal, though...).
>
>     florian> Thanks,
>     florian> Florian
>
>
>
>     florian> ______________________
>     florian> Florian Koller
>     florian> GfK Fernsehforschung GmbH
>     florian> Research Consulting & Development
>     florian> Nordwestring 101
>     florian> D-90319 Nürnberg
>     florian> Fon  +49 (0)911 395-3554
>     florian> Fax  +49 (0)911 395-4130
>     florian> www.gfk.de / www.gfk.com
>
>
>
>     florian> _________________________
>
>     florian> Diese E-Mail (ggf. nebst Anhang) enthält vertrauliche
> und/oder rechtlich
>     florian> geschützte Informationen. Wenn Sie nicht der richtige
> Adressat sind, oder
>     florian> diese E-Mail irrtümlich erhalten haben, informieren Sie
> bitte sofort den
>     florian> Absender und vernichten Sie diese Mail. Das unerlaubte
> Kopieren sowie die
>     florian> unbefugte Weitergabe dieser Mail ist nicht gestattet.
>
>     florian> This e-mail (and any attachment/s) contains
> confidential and/or privileged
>     florian> information. If you are not the intended recipient (or
> have received this
>     florian> e-mail in error) please notify the sender immediately
> and destroy this
>     florian> e-mail. Any unauthorised copying, disclosure or
> distribution of the
>     florian> material in this e-mail is strictly forbidden.
>
>     florian> ______________________________________________
>     florian> R-help at stat.math.ethz.ch mailing list
>     florian> https://stat.ethz.ch/mailman/listinfo/r-help
>     florian> PLEASE do read the posting guide! http://www.R-project.
> org/posting-guide.html



More information about the R-help mailing list