简体   繁体   中英

R plot legend: Reduce space between legend columns

I am using vegan library to make some plots, with this code:

raremax <- min(colSums(mydata))
col <- palette()
lty <- c("solid", "dashed", "longdash", "dotdash")
pars <- expand.grid(col = col, lty = lty, stringsAsFactors = FALSE)

out <- with(pars[1:18, ], rarecurve(mydata, step = 100, sample = raremax, 
       cex =0.6, ylab="OTUs", label=F, col=col, lty=lty, lwd=2))

Then I add a legend using this code:

legend("bottomright", names(mydata), col=pars[1:18,1], lty= pars[1:18,2], 
       lwd=2, cex=0.5, xjust=1, ncol=2, x.intersp=0.5, y.intersp=0.5, bg="white")

The resulting graph looks like this: 在此处输入图片说明

I would like to reduce the space between legend columns, also reducing the size of the legend box, but I can't find a way to do that.

Anyone could provide me some help?

A combination of the legend() parameters "x.intersp" and "text.width" should be helpful.

Decreasing "x.intersp" (default value = 1, for me 0.25 looked good) should move your the legend labels closer to their respective points. Decreasing "text.width" (default value=NULL, for me 0.045 looked good) moves the columns closer together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM