Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce size of legend area in barplot

Tags:

plot

r

legend

I can't reduce the size of the legend in this plot. Could someone help me out? I want it to appear topright, but with no more than 20% of the height of plot area

a <- c(3, 2, 2, 2, 1, 2 ) barplot(a, beside = T, col = 1:6, space = c(0, 2)) legend("topright", legend = c("a", "b", "c", "d", "e", "f"), fill = 1:6, ncol = 2) 
like image 948
Sergio.pv Avatar asked Jun 23 '14 08:06

Sergio.pv


People also ask

How do you reduce the size of a legend in Python?

Steps. Create line1 and line2 using two lists with different line widths. To place a legend on the figure and to adjust the size of legend box, use borderpad=2 in legend() method. To display the figure, use show() method.

How do you make a legend smaller in Matlab?

You can change the font size for a MATLAB legend by setting the 'FontSize' property of the Legend object. For example, plot four lines. Create a legend and assign the Legend object to the variable 'lgd'. Then, use dot notation to access the 'FontSize' property and set the value to 14 points.

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.


1 Answers

The cex parameter will do that for you.

a <- c(3, 2, 2, 2, 1, 2 ) barplot(a, beside = T,         col = 1:6, space = c(0, 2)) legend("topright",         legend = c("a", "b", "c", "d", "e", "f"),         fill = 1:6, ncol = 2,        cex = 0.75) 

The plot

like image 197
Anders Ellern Bilgrau Avatar answered Sep 20 '22 13:09

Anders Ellern Bilgrau