I have a map of shapes that are labelled with numbers 1:200. I want to create a legend that decodes these numbers. So I tried (keeping it to 20 for easy reading).
plot(c(1,20), c(0,3), type="n")
xx <- c(0,1,1,0)
thelabels <- paste(LETTERS[1:20], LETTERS[1:20], sep="")
for (i in 1:20){
polygon(xx, c(0,0,1,1))
text(mean(xx), 0.5, i)
xx <- xx + 1
}
legend("topleft", "groups",
legend = thelabels, pch=as.character(c(1:20)),
ncol=4
)

However, this doesn't work because pch only admits 1-length strings. How can I create a legend where the key is based on the numbers 1:200 not just the first digit of each? or do something equivalent to forcing pch into accepting multilength strings? (Note that thelabels contains longer text so I can't directly label the shapes with thelabels.)
Here's a total kludge workaround:
plot(c(1,20), c(0,3), type="n")
xx <- c(0,1,1,0)
thelabels <- paste(1:20, " ", LETTERS[1:20], LETTERS[1:20], sep="")
for (i in 1:20){
polygon(xx, c(0,0,1,1))
text(mean(xx), 0.5, i)
xx <- xx + 1
}
legend("topleft", "groups",
legend = thelabels, pch="",
ncol=4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With