Victor Gabillon
2011-Apr-29 03:21 UTC
[R] Change the text size of the title in a legend of a R plot.
Hello, Is it possible to change the text size of the title in a legend of a R plot? I tried to directly change the title.cex argument but it seems not to work. Trying : Horizo <- c(1,2,6,10,20) legtext <- paste(Horizo,sep="") legend("topleft", legend=legtext,col=col,text.col=col,lwd=lwd, lty=lty,cex=1.1,ncol=3,title = "Horizons",title.col ="black",title.cex=1.4) gives the following error (sorry in french): Erreur dans legend("topleft", legend = legtext, col = col, text.col = col, : argument(s) inutilis?(s) (title.cex = 1.4) saying title.cex argument as been ignored. Thank you for helping. Victor
Steven McKinney
2011-Apr-29 05:15 UTC
[R] Change the text size of the title in a legend of a R plot.
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Victor Gabillon > Sent: April-28-11 8:22 PM > To: r-help at r-project.org > Subject: [R] Change the text size of the title in a legend of a R plot. > > Hello, > > Is it possible to change the text size of the title in a legend of a R plot? > > I tried to directly change the title.cex argument but it seems not to work. > > Trying : > > Horizo <- c(1,2,6,10,20) > legtext <- paste(Horizo,sep="") > legend("topleft", legend=legtext,col=col,text.col=col,lwd=lwd, > lty=lty,cex=1.1,ncol=3,title = "Horizons",title.col ="black",title.cex=1.4)I haven't found any cex argument that works for just the legend title, but you can get some modification of the title with the expression argument: legend("topleft", legend=legtext,col=col,text.col=col,lwd=lwd, lty=lty,cex=1.1,ncol=3, title = expression(bold("Horizons")),title.col="black") Does that help? Otherwise, you can of course figure out which functions do the legend plotting, copy and modify those to get a title cex in place. Steve McKinney> > gives the following error (sorry in french): > Erreur dans legend("topleft", legend = legtext, col = col, text.col > col, : > argument(s) inutilis?(s) (title.cex = 1.4) > > saying title.cex argument as been ignored. > > Thank you for helping. > > Victor > > ______________________________________________ > 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.
Jannis
2011-Apr-29 08:03 UTC
[R] Change the text size of the title in a legend of a R plot.
On 04/29/2011 05:21 AM, Victor Gabillon wrote:> Horizo <- c(1,2,6,10,20) > legtext <- paste(Horizo,sep="") > legend("topleft", legend=legtext,col=col,text.col=col,lwd=lwd, > lty=lty,cex=1.1,ncol=3,title = "Horizons",title.col > ="black",title.cex=1.4)I am not sure, but the manual regarding legend seems to be not correct (or at least misleading). There is not title.cex argument for legend (even though the help page mentions it). Either you set cex >1 but this will resize the labels as well. Or you modify the code of legend as follows: change the following (near the end of the code): text2(left + w/2, top - ymax, labels = title, adj = c(0.5, 0), cex = cex, col = title.col) to: text2(left + w/2, top - ymax, labels = title, adj = c(0.5, 0), cex = title.cex, col = title.col) and add title.cex to the arguments of legend. Its probably easiest if you copy the code of legend and save its modified version within a different function. Not sure on whom to contact regarding correcting the documentation of legend(). Perhaps even I am wrong, but I could not find any reference to title.cex in the code. HTH Jannis
Victor Gabillon
2011-Apr-29 11:56 UTC
[R] Change the text size of the title in a legend of a R plot.
thanks everyone for the help. I ended up copying and pasting the legend function from the R source files. I changed it so that the title.cex is not set by default to cex and so that this title.cex can be given as a parameter. It works fine for me. Note that if you make the title too big it goes out of the border as the borders were not designed for the case of a big title. Thanks again!! Victor Le 29/04/2011 10:03, Jannis a ?crit :> On 04/29/2011 05:21 AM, Victor Gabillon wrote: >> Horizo <- c(1,2,6,10,20) >> legtext <- paste(Horizo,sep="") >> legend("topleft", legend=legtext,col=col,text.col=col,lwd=lwd, >> lty=lty,cex=1.1,ncol=3,title = "Horizons",title.col >> ="black",title.cex=1.4) > > I am not sure, but the manual regarding legend seems to be not correct > (or at least misleading). There is not title.cex argument for legend > (even though the help page mentions it). Either you set cex >1 but > this will resize the labels as well. Or you modify the code of legend > as follows: > > change the following (near the end of the code): > > text2(left + w/2, top - ymax, labels = title, adj = c(0.5, > 0), cex = cex, col = title.col) > > to: > > text2(left + w/2, top - ymax, labels = title, adj = c(0.5, > 0), cex = title.cex, col = title.col) > > and add title.cex to the arguments of legend. Its probably easiest if > you copy the code of legend and save its modified version within a > different function. > > Not sure on whom to contact regarding correcting the documentation of > legend(). Perhaps even I am wrong, but I could not find any reference > to title.cex in the code. > > HTH > Jannis