如何在R中绘制三角形作为图例?

时间:2013-01-18 07:15:34

标签: r legend

我正在制作一个我需要绘制图例的情节,我要求其中一个是三角形。

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

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

此致

2 个答案:

答案 0 :(得分:4)

使用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))

答案 1 :(得分: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"))