传奇中的线宽?

时间:2013-03-15 14:25:31

标签: r plot

我想更改图例中线条的宽度。目前我有:

legend(-0.145, 25, c("(Gaussian) Kernel density","fitted normal distribution"),lwd=1.8, cex=0.8, 
   col=c("black","black"), lty=1:2)

lwd似乎改变了文字,但没有改变线条和虚线的宽度,我该怎么办呢?

2 个答案:

答案 0 :(得分:2)

我认为你错了,lwd设置了你的图例中的线宽:

比较这个(上图):

plot(rnorm(100)*13)
legend(-0.145, 25, c("(Gaussian) Kernel density","fitted normal distribution"),lwd=0.1, cex=0.8, 
   col=c("black","black"), lty=1:2)

这个(底部情节):

plot(rnorm(100)*13)
legend(-0.145, 25, c("(Gaussian) Kernel density","fitted normal distribution"),lwd=3, cex=0.8, 
   col=c("black","black"), lty=1:2)

enter image description here

答案 1 :(得分:1)

您可以使用图例函数seg.len的参数来减小图例的大小。

这里有个例子:

    set.seed(55) # Set the seed of R‘s random number generator
    x <- runif(10, min=0, max=100) # Generating random numbers
    plot(x, type="l") # plot x as line
    legend("topright", "x", lty="solid") # add legend

enter image description here

和修改legend函数的相同代码:

    plot(x, type="l")
    legend("topright", "x", lty="solid",seg.len=0.5) # modify length of the line in the legend

enter image description here