Hello,
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:
http://r.789695.n4.nabble.com/file/n4129402/example.png
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.
par(lheight=2)
plot(1,1,col="white")
legend("center", legend=c(expression(paste("Observed
",italic(bar(EC)[e]))),expression(paste("Simulated
",italic(bar(EC)[e]))),"test1","test2"),
lty = c(NA,NA,1,1),
col =
c("black","black","red","blue"),
density = c(NA,25,NA,NA),
border=c("black","black",NA,NA),
fill = c("grey","black",NA,NA),
angle = c(NA,45,NA,NA),
cex = 1.25, bty = "n", xpd = TRUE)
> sessionInfo()
R version 2.13.2 (2011-09-30)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] 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.
On Thu, Dec 1, 2011 at 11:54 AM, emorway <emorway at usgs.gov> wrote:> Hello, > > 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: > > http://r.789695.n4.nabble.com/file/n4129402/example.png > > 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. > > par(lheight=2) > plot(1,1,col="white") > > legend("center", legend=c(expression(paste("Observed > ",italic(bar(EC)[e]))),expression(paste("Simulated > ",italic(bar(EC)[e]))),"test1","test2"), > ? ? ? lty = c(NA,NA,1,1), > ? ? ? col = c("black","black","red","blue"), > ? ? ? density = c(NA,25,NA,NA), > ? ? ? border=c("black","black",NA,NA), > ? ? ? fill = c("grey","black",NA,NA), > ? ? ? angle = c(NA,45,NA,NA), > ? ? ? cex = 1.25, bty = "n", xpd = TRUE) >For #1 it would be easier to just use 2 columns so that there is no question of alignment in the first place, i.e. ncol = 2. For #2 try drawing the legend from lower level functions such as text since text does respect lheight. See the source of legendg in plotrix for how to do that. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On 2011-12-01 08:54, emorway wrote:> Hello, > > 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: > > http://r.789695.n4.nabble.com/file/n4129402/example.png > > 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. > > par(lheight=2) > plot(1,1,col="white") > > legend("center", legend=c(expression(paste("Observed > ",italic(bar(EC)[e]))),expression(paste("Simulated > ",italic(bar(EC)[e]))),"test1","test2"), > lty = c(NA,NA,1,1), > col = c("black","black","red","blue"), > density = c(NA,25,NA,NA), > border=c("black","black",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; Try replacing expression(paste("Observed",italic(bar(EC)[e]))) with expression("Observed"~italic(bar(EC)[e])) Peter Ehlers> >> sessionInfo() > R version 2.13.2 (2011-09-30) > Platform: x86_64-pc-mingw32/x64 (64-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 > [2] LC_CTYPE=English_United States.1252 > [3] LC_MONETARY=English_United States.1252 > [4] LC_NUMERIC=C > [5] LC_TIME=English_United States.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > loaded via a namespace (and not attached): > [1] 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 > 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.