将图例拆分为两行

时间:2017-06-30 13:32:53

标签: r legend

我一直试图将我的传奇分成两行,但没有成功(或另一种尝试是添加一个新的传奇)。 我的传奇代码就像这样:

legend("top",c("P1","P2", "P3", "P4","P5","P6"),lty=c(1,3,3,1,3,3),lwd=2,bty="n", col=c("deepskyblue2","deepskyblue2","red","deepskyblue2","deepskyblue2","red"))

我希望P1,P2,P3在同一条线上,然后在第二条线右下方的P4,P5,P6。 请有人帮我一下。

非常感谢。

1 个答案:

答案 0 :(得分:5)

您可以使用ncol中的legend选项包含3列(和2行)。您还必须将它们编入索引以逐行获取订单。

plot(1:10)
legend_order <- matrix(1:6,ncol=3,byrow = TRUE)
legend("top",c("P1","P2", "P3", "P4","P5","P6")[legend_order],
       lty=c(1,3,3,1,3,3)[legend_order],
       lwd=2,bty="n", 
       col=c("deepskyblue2","deepskyblue2","red",
             "deepskyblue2","deepskyblue2","red")[legend_order],
       ncol=3)

enter image description here