Sergio.pv - 4 months ago 30

R Question

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

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)
```