[R] legend, "lheight", and alignment
ehlers at ucalgary.ca
Fri Dec 2 02:01:31 CET 2011
On 2011-12-01 08:54, emorway wrote:
> A bit of fairly simple code, yet I don't seem to be able to manipulate it
> quite as much as I would like:
> 1) It would be nice if the objects appearing in the legend were aligned,
> and by aligned I mean the boxes are centered over the lines. Do I need to
> adjust the use of "NA" in the code below to accomplish this? Here's how it
> appears on my machine:
> 2) Because I'm using a call to 'expression' in the text contained in the
> legend, it would be nice to space the lines of text a bit more. My feeble
> attempt was to increase the lheight parameter in the hopes this would affect
> the legend...to no avail. Further, lheight cannot be added to the argument
> list of legend. I've been unable to track down another parameter applicable
> to legend, suggestions very much appreciated.
> legend("center", legend=c(expression(paste("Observed
> lty = c(NA,NA,1,1),
> col = c("black","black","red","blue"),
> density = c(NA,25,NA,NA),
> fill = c("grey","black",NA,NA),
> angle = c(NA,45,NA,NA),
> cex = 1.25, bty = "n", xpd = TRUE)
You can adjust the alignment a little by adding 'merge = TRUE';
this will left-align both the boxes and the lines.
For your second question, use the y.intersp argument, e.g.
'y.intersp = 2'.
You might also avoid using 'paste' in your expressions;
> R version 2.13.2 (2011-09-30)
> Platform: x86_64-pc-mingw32/x64 (64-bit)
>  LC_COLLATE=English_United States.1252
>  LC_CTYPE=English_United States.1252
>  LC_MONETARY=English_United States.1252
>  LC_NUMERIC=C
>  LC_TIME=English_United States.1252
> attached base packages:
>  stats graphics grDevices utils datasets methods base
> loaded via a namespace (and not attached):
>  tools_2.13.2
> View this message in context: http://r.789695.n4.nabble.com/legend-lheight-and-alignment-tp4129402p4129402.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help