Re: [R] Change the text size of the title in a legend of a R plot.

From: Remko Duursma <remkoduursma_at_gmail.com>
Date: Fri, 29 Apr 2011 15:59:37 +1000

Hi Victor,

looking at the code for legend, it looks like the same 'cex' value is used for the text in the legend as the title.

Here is a trick though: draw the legend twice, with different cex values, and omitting title or text:

plot(1)
legend("topright",c("a","b"),title=" ")
legend("topright",c(" "," "),title="Legend",cex=0.6, bty='n', title.adj=0.15)

A bit of a hack but it works....
If you want the title larger, it will probably not fit the box, which you can omit by setting bty='n' (as in the second line).

good luck,

Remko



Remko Duursma
Research Lecturer

Centre for Plants and the Environment
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Mobile: +61 (0)422 096908
www.remkoduursma.com

On Fri, Apr 29, 2011 at 3:15 PM, Steven McKinney <smckinney_at_bccrc.ca> wrote:
>
>
>
>> -----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.
>
> ______________________________________________
> 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.
>



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. Received on Fri 29 Apr 2011 - 06:10:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 29 Apr 2011 - 06:30:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive