[R] legend: height of entries

Stefan Richter stefan.stafra at web.de
Mon Feb 28 13:13:06 CET 2011


Hello,

Am 28.02.2011 um 12:57 schrieb Sarah Goslee:

> Stefan,
> 
> I'm not entirely certain what you're doing. Providing a working example would
> make it much easier for us to offer suggestions. The graphics system you're
> using matters, for instance.
> 
> Sarah

Thank you for your replay, Sarah!

I use MacOSX, X11.
I took an example from the legend help:

x <- 1:5; y1 <- 1/x; y2 <- 2/x
 plot(rep(x, 2), c(y1, y2), type="n", xlab="x", ylab="y")
 lines(x, y1); lines(x, y2, lty=2)
 legend("topright", legend = c("A", "B", "ABCABCABC", "D"),
                lty = 1:2, xjust = 1, yjust = 1,
                title = "Line Types", horiz = T)

The legend is horizontal, and there are four entries. All entries have the same width (the width of "ABCABCABC", because it is the longest). Is there a possibility to change the arguments of the legend so that all entries get only the width they need (and that the legend in this example fits entirely within the plot)?

Stefan Richter


More information about the R-help mailing list