【问题标题】:How to draw triangle as legend in R?如何在R中绘制三角形作为图例?
【发布时间】:2013-01-18 07:15:33
【问题描述】:

我正在绘制一个图例,我需要绘制图例,并且我需要其中一个是三角形。

  plot.new()
  legend(x=.5,y=.9, c("A","B","C","D"), cex=.8, bty="n", 
         fill = c("green","yellow","red","blue"))

我希望legend D三角形。我该如何实现?

问候

【问题讨论】:

    标签: r legend


    【解决方案1】:

    使用pchcol(而不是fill):

    plot.new()
    legend(x=.5,y=.9, c("A","B","C","D"), cex=.8, bty="n",
           col=c("green", "yellow", "red", "blue"), pch=c(15, 15, 15, 17))
    

    【讨论】:

    • 如何增加图例的大小?
    • 使用cex 和/或pt.cex 参数(字符扩展因子)
    【解决方案2】:

    pch参数选择图例符号的形状:

         plot.new();
    
         legend(x=.5,y=.9, c("A","B","C","D"), 
                pch=c(1,4,3,2), cex=.8, bty="n",
                col=c("green","yellow","red","blue"))
    

    【讨论】:

    • 谢谢!但是三角形是空心的。如何填充颜色。
    • 符号编号 17 将为您提供一个实心三角形,因此只需将 pch 参数中的 2 替换为 17
    • ?points 将为您提供使用pch 可以获得的所有可能的点形状。
    猜你喜欢
    • 1970-01-01
    • 2021-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多