Reduce size of legend area in barplot

Sergio.pv picture Sergio.pv · Jun 23, 2014 · Viewed 144.1k times · Source

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)

Answer

Anders Ellern Bilgrau picture Anders Ellern Bilgrau · Jun 23, 2014

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