Skip to content
Back to formatted view

Raw Message

Message-ID: <49F82905.4060604@bitwrit.com.au>
Date: 2009-04-29T10:16:37Z
From: Jim Lemon
Subject: legend with small colored boxes
In-Reply-To: <4DA7E67F-4C17-4147-B7DB-99E2EE2C10C3@gmail.com>

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