首页 文章

R指定点边框颜色与填充和线不同

提问于
浏览
3

这与points border color and line color is different between legend box and whole plot box when pch=21有关

我有一个填充点(pch = 21),黑色边框和绿色填充的情节,但我也有错误的胡须,与填充颜色颜色相同 . 我知道我可以使用“col”和“pt.bg”的组合来匹配图例中的点,但是线条颜色与点边界匹配,这不是我需要的:

x=1:10
y=runif(10)
plot(x,y,lwd=3,col="black",bg="green",pch=21,cex=2)
arrows(x,y-0.05,x,y+0.05,lwd=3,col="green",angle=90,code=3)
legend(5,0.8,col="black",pt.bg="green",lwd=3,pch=21,legend="text",cex=2)

给出以下......

enter image description here

有没有一种方法可以使用点边框为黑色的传奇绿线和绿色填充点?更好的是有胡须,但我认为这可能不可能......

1 回答

  • 1

    拨打两个 legend 电话 . 一个用 bg = NA 绘制线,另一个用 bty = "n" 绘制点:

    set.seed(1)
    x=1:10
    y=runif(10)
    plot(x, y, lwd = 3, col = "black", bg = "green", pch = 21, cex = 2)
    arrows(x, y-0.05, x, y+0.05, lwd = 3, col = "green", angle = 90, code = 3)
    legend("topright",
           col="green",
           lwd = 3,
           lty = 1,
           legend = "text",
           cex = 2,
           bg = NA)
    legend("topright",
           col = "black",
           pt.bg = "green",
           pch = 21,
           lwd = 3,
           legend = "text",
           cex = 2,
           lty = 0,
           bty = "n")
    

    enter image description here

相关问题