简体   繁体   English

如何在R图例中移动符号

[英]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). 我正在使用标准R绘图(不是ggplot或其他任何东西)。 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. 只为寻找文档, xjust的说法legend设置图例理由。

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. 只需将x.intersp添加到图例中,然后播放应移动的矢量的条目即可。 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))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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