简体   繁体   English

R:图例的位置和图例中线条的长度

[英]R: positioning of the legend and length of the lines in the legend

I can't set the location of the legend properly, I have tried to play around with xjust and ncol but it still appears in the middle of the graphic. 我无法设置图例的位置正确,我试图玩弄xjustncol ,但它仍然会出现在图形的中间。

Can you help it align it to the border (left or right I do not care)? 你能帮助它将它与边界对齐(左边或右边我不在乎)?

Moreover is it possible to draw shorter lines in the legend? 此外,是否可以在图例中画出较短的线条? These appear too long. 这些看起来太长了。

 par(mar=c(5,4,4,5)+.1)
 plot(1:109,rnorm(109), type="l",col="blue", lwd=2, 
      main="Compare signal and std deviation MC3 ch44",
      ylab="signal", xlab="locations")
 par(new=TRUE)
 plot(1:109, rnorm(109), ylab="",xlab="", type="l", 
      col="red",xaxt="n",yaxt="n", lwd=2)
 axis(4)
 mtext("std. deviation",side=4,line=3)
 legend("topright",col=c("blue", "red"), lwd=2,
        legend=c("signal","std dev"), cex=0.85, bty="n", xjust=1)

As pointed out in the comments restarting an R session and using 正如在重新启动R会话和使用的注释中所指出的那样

legend("topright",col=c("blue", "red"), lwd=2,
 legend=c("signal","std dev"), cex=0.85, bty="n", xjust=1, seg.len=0.5)

solved my problems. 解决了我的问题。

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

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