代码之家  ›  专栏  ›  技术社区  ›  ClimateUnboxed

r指定与填充和线条不同的点边框颜色

  •  3
  • ClimateUnboxed  · 技术社区  · 8 年前

    这与 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 回复  |  直到 8 年前
        1
  •  1
  •   missuse    8 年前

    使两 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

    推荐文章