In my diagram, I encode some information in the diameter of the circles drawn. My question is: what is the easiest way to document this information in a legend?
Here is what I have tried so far:
dat <- rnorm(100)
cex_brks <- quantile(dat, c(0.25,0.5,0.75))
cex_size <- c(1,1.4,1.8, 2.2)
cex <- rep(NA, length(dat))
for (i in 1:3) {
cex[is.na(cex) & dat<=cex_brks[[i]]] <- cex_size[[i]]
}
cex[is.na(cex)] <- cex_size[[4]]
plot(dat, cex=cex, pch=21)
legend(
"bottom",
legend=c("very small", "small", "large", "very large"),
bty="n",
pch=21,
cex=cex_size
)
However, doing so in this way changes not only the character (pch), but also the legend text. How can I override this so that only the legend symbols are of different sizes?
source
share