[R] Unwanted boxes in legend

Peter Ehlers ehlers at ucalgary.ca
Thu Apr 15 20:13:40 CEST 2010


On 2010-04-15 11:10, Steve Murray wrote:
>
> Dear all,
>
> I am using the following code to generate a legend in my plot (consisting of both bars and points), but end up with boxes around my points:
>
> legend(10, par("usr")[4], c("A", "B", "C", "D"), fill=c(NA,NA, "grey28", NA), pch=c(16,4,NA,18), col=c("red","blue","grey28","yellow"), lty=FALSE, bty="n", horiz=FALSE)
>
> I want a box around the third element of the legend (to represent the bar 'fill' colour), but not for the others, where points are shown instead.
>
> What am I doing wrong above and how do I correct it?

Add the 'border' argument:

either

  border = FALSE  # in which case no box is drawn for any element

or

  border = c(NA, NA, "black", NA)

  -Peter Ehlers

>
> Many thanks,
>
> Steve
>   		 	   		
>
> ______________________________________________
> 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.
>
>

-- 
Peter Ehlers
University of Calgary



More information about the R-help mailing list