Plot a legend outside of the plotting area in base graphics?

前端 未结 10 920
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 14:48

As the title says: How can I plot a legend outside the plotting area when using base graphics?

I thought about fiddling around with layout

10条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 15:32

    I can offer only an example of the layout solution already pointed out.

    layout(matrix(c(1,2), nrow = 1), widths = c(0.7, 0.3))
    par(mar = c(5, 4, 4, 2) + 0.1)
    plot(1:3, rnorm(3), pch = 1, lty = 1, type = "o", ylim=c(-2,2))
    lines(1:3, rnorm(3), pch = 2, lty = 2, type="o")
    par(mar = c(5, 0, 4, 2) + 0.1)
    plot(1:3, rnorm(3), pch = 1, lty = 1, ylim=c(-2,2), type = "n", axes = FALSE, ann = FALSE)
    legend(1, 1, c("group A", "group B"), pch = c(1,2), lty = c(1,2))
    

    an ugly picture :S

提交回复
热议问题