Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

r legend trouble , how to change the text size in legend

Tags:

plot

r

legend

I think cex doesn't work. Cex will change the whole scale of the legend. But I just want to enlarge the text size. any command will help?

like image 236
zhuoer Avatar asked Jun 03 '13 20:06

zhuoer


People also ask

How do I change the text size in legend in R?

To change the legend size of the plot, the user needs to use the cex argument of the legend function and specify its value with the user requirement, the values of cex greater than 1 will increase the legend size in the plot and the value of cex less than 1 will decrease the size of the legend in the plot.

How do you change the legend in R?

In order to change the legend size in R you can make use of the cex argument. Values bigger than 1 will lead to a bigger legend and smaller to smaller legends than the default.

What is Cex in legend in R?

cex. character expansion factor relative to current par("cex") . Used for text, and provides the default for pt. cex . pt.cex.


2 Answers

Yes!, set pt.cex = 1 and change cex as you want as in:

plot(c(1,1)) legend("topleft", "Legend", cex=1.3, pch=1, pt.cex = 1) 
like image 198
Jilber Urbina Avatar answered Sep 23 '22 12:09

Jilber Urbina


You can set the cex for the points separately from the rest of the legend. This would still make the box small, though. A more specific example of what you're trying to do might help. However, see if this solves your problem:

plot(rnorm(10)) legend("top", legend="test", pch=21) #everything is normal sized (cex=1 default from par()) legend("topleft", legend="test", pch=21, cex=0.5) #everything is small legend("topright", legend="test", pch=21, pt.cex=1, cex=0.5) #the point is normal, but the rest is small 

Best of luck :)

like image 45
rbatt Avatar answered Sep 23 '22 12:09

rbatt