Reputation: 1814
I am creating a legend without a plot, but part of the items are left out, how can I avoid stuff kept out? A possible way would be to reduce the space between the items. That's what I have done
plot(1, type="n", axes=FALSE, xlab="", ylab="")
legend("bottomleft", bty = "n",inset = c(-0.2, 0),
legend = c("AA","ABC","DEF","GHI","LMO","AAABBB","ABC ABCDEF"),
col=c(AA = "#8b5a00", ABC = "#5d8f21", DEF = "#9f69ee",
GHI = "#ec4e01", LMO = "#b9c000", AAABBB = "#12a0a5", "ABCDEF" = "tan1"),
pch=16, cex=1, xjust=0.5, yjust=0.5, horiz=T, xpd = TRUE, x.intersp=0.5)
Upvotes: 0
Views: 388
Reputation: 1814
I have found that text.width can control width legend text horizontally (x coordinates), first value refers to the position of the first item.
legend("bottomleft", text.width=c(0,0.046,0.052,0.056,0.056,0.059,0.069)
...
Upvotes: 0
Reputation: 11860
The plot window needs to be sufficiently large, you can just call it directly in pdf()
or png()
with enough width:
png("test.png", width=1000)
plot.new()
# Your legend
dev.off()
Upvotes: 1