简体   繁体   中英

How to move the symbols in R legend

I want to move the dotted line to the right so that (ideally) the centers of the boxes and the center of the line are aligned. I am using standard R plots (not ggplot or anything). The code I used for creating the legend so far is the following:

legend("topright", legend=c("[0,1st quant.]","(1st quant., 2nd quant.]", "(2nd quant., 3rd quant.]", "(3rd quant., maximum]", "Poi(137.205) density"), fill=c(cols[-1],NA), lty=c(NA,NA,NA,NA,3),cex=0.8, box.lty = 0, border=c(1,1,1,1,"white"))

Histogram the legend has to be adapted for 图例的直方图必须适应

looking only for the doc, xjust argument for legend sets the legend justification.

Also, let me add another tip: before considering the legend, add a title to your plot, it's far more important ;)

I found out the answer, maybe it will be helpful for others at some time. Just add x.intersp to the legend and play around with the entry of the vector that should be moved. Increasing the number will move the symbol/line/box to the left.

legend("topright", legend=c("[0,1st quant.]","(1st quant., 2nd quant.]", "(2nd quant., 3rd quant.]", "(3rd quant., maximum]", "Poi(137.205) density"), fill=c(cols[-1],NA), lty=c(NA,NA,NA,NA,3),cex=0.8, box.lty = 0, border=c(1,1,1,1,"white"), x.intersp = c(1,1,1,1,2.2))

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