Change the size of the text in legend according to the length of the legend vector in the graph
Posted
by
user1021713
on Stack Overflow
See other posts from Stack Overflow
or by user1021713
Published on 2012-10-08T08:34:35Z
Indexed on
2012/10/08
9:37 UTC
Read the original article
Hit count: 500
I have to draw a 20 plots and horizontally place a legends in each plots.
I gave the following command for the first plot:
plot(x=1:4,y=1:4)
legend("bottom",legend = c("a","b","c","d"),horiz=TRUE,text.font=2,cex=0.64)
then for the second plot I tried :
plot(x=1:2,y=1:2)
legend("bottom",legend = c("a","b"),horiz=TRUE,text.font=2,cex=0.64)
But because the size of the character vector passed to legend argument are different I get the size of the legend different.
Since I have to plot so many different plots having varying sizes of legends,I would want to do it in an automated fashion.
Is there a way to do this which can fix the size of the legend in all the plots and fit it to graph size?
© Stack Overflow or respective owner