An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090429/443fe49c/attachment-0001.pl>
legend with small colored boxes
4 messages · Cuvelier Etienne, Jim Lemon, Christophe Dutang
Christophe Dutang a ?crit :
Hi all, I tried to a nice legend with small boxes filled with the colors used for the plots. But it does nor work, boxes are always filled with black. An example is here plot(1:4,1:4) lines(1:4,4:1, col="blue")
#try something like this
legend("top",leg=c("a","b"),fill=1:2)
Etienne
legend("top",leg=c("a","b"),col=c("black","blue"), fill=TRUE)
How could I specify the colors? the argument col.box is the color of
the whole legend box...
Thanks in advance
Christophe
PS : I work with R 2.9.0.
--
Christophe Dutang
Ph. D. student at ISFA, Lyon, France
website: http://dutangc.free.fr
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Christophe Dutang wrote:
Hi all,
I tried to a nice legend with small boxes filled with the colors used
for the plots. But it does nor work, boxes are always filled with black.
An example is here
plot(1:4,1:4)
lines(1:4,4:1, col="blue")
legend("top",leg=c("a","b"),col=c("black","blue"), fill=TRUE)
How could I specify the colors? the argument col.box is the color of
the whole legend box...
Ah Cristophe, you have been waylaid by the coercion of types. The fill
argument specifies the colors of the boxes, and you have sent it TRUE.
As TRUE happens to be equal to 1, legend is fooled into filling the
boxes with the color assigned the number 1, which is black. Try:
legend(...,fill=c("black","blue"),...)
Jim
I thought I have tried to pass a vector of "colors" and that it did not work.. Thanks for all! Christophe Le 29 avr. 09 ? 12:16, Jim Lemon a ?crit :
Christophe Dutang wrote:
Hi all,
I tried to a nice legend with small boxes filled with the colors
used for the plots. But it does nor work, boxes are always filled
with black.
An example is here
plot(1:4,1:4)
lines(1:4,4:1, col="blue")
legend("top",leg=c("a","b"),col=c("black","blue"), fill=TRUE)
How could I specify the colors? the argument col.box is the color
of the whole legend box...
Ah Cristophe, you have been waylaid by the coercion of types. The
fill argument specifies the colors of the boxes, and you have sent
it TRUE. As TRUE happens to be equal to 1, legend is fooled into
filling the boxes with the color assigned the number 1, which is
black. Try:
legend(...,fill=c("black","blue"),...)
Jim
-- Christophe Dutang Ph. D. student at ISFA, Lyon, France website: http://dutangc.free.fr