Jürgen Biedermann
2011-Aug-21 20:50 UTC
[R] Increase the size of the boxes but not the text in a legend
HI there, I want to add a legend to a plot using the density and angle argument, so patterns with lines in different angles are used in the plot and should be referred to. When I use default settings, the filled boxes are too small. With the cex argument I can enlarge the whole legend, but then the text gets too big. How could I just increase the size of the single boxes and not the text. I tried: legend("topright", c("Trefferquote","Falschalarmquote"), density=c(20,16), angle=c(45,0),cex=1.5, y.intersp=0.8) The sizes of the boxes are good now, but the text is too large and so also the whole legend box gets too big. Thank you very much for your help J?rgen
Jean V Adams
2011-Aug-22 12:48 UTC
[R] Increase the size of the boxes but not the text in a legend
> [R] Increase the size of the boxes but not the text in a legend > Jürgen Biedermann > to: > r-help > 08/21/2011 06:02 PM > > HI there, > > I want to add a legend to a plot using the density and angle argument, > so patterns with lines in different angles are used in the plot and > should be referred to. > When I use default settings, the filled boxes are too small. > With the cex argument I can enlarge the whole legend, but then the text > gets too big. > > How could I just increase the size of the single boxes and not the text.There is no way to do this with the legend() function. The cex= argument controls both the text and the box size. You could either write your own code to place rectangles and text on your plot, or you could create a modified version of the legend() function to suit your needs. Jean> > I tried: > > legend("topright", c("Trefferquote","Falschalarmquote"), > density=c(20,16), angle=c(45,0),cex=1.5, y.intersp=0.8) > > The sizes of the boxes are good now, but the text is too large and so > also the whole legend box gets too big. > > Thank you very much for your help > Jürgen[[alternative HTML version deleted]]
alles.khan
2012-Apr-20 15:48 UTC
[R] Increase the size of the boxes but not the text in a legend
Although an old topic, To follow-up on the suggestion to alter the legend function. Type "legend" in R, copy-paste the appearing code into you code-editor and search for the line points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok], the cex function controls the scaling, so you want the pt.cex become larger, Change this line into, for example points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok]+1.5, than you run in R legend_large_box <- function (x, y ....etc.etc. the whole bunch of with the altered legend code and call the function legend_large_box within the plotting. It worked for me. -- View this message in context: http://r.789695.n4.nabble.com/Increase-the-size-of-the-boxes-but-not-the-text-in-a-legend-tp3759137p4574455.html Sent from the R help mailing list archive at Nabble.com.