如何使用2列制作R图例?

Fel*_*han 10 plot r legend

我想在我的图表上创建一个由plot()函数生成的图例.原始legend()函数将生成一个只有1列的列表.如何制作有2列的图例?

想要传奇

koe*_*ker 9

我无法在一次调用legend标准图中找到方法.

这是一个选项,绘制两个单独的图例:一个带有线和点,一个带有标签.x.intersp可用于调整标签和线条之间的距离.

plot(cumsum(runif(n = 100)))

# draw legend with lines and point but without labels and box. x.intersp controls horizontal distance between lines
L = legend(x = 'bottom', legend = rep(NA,4), col=1:2, lty=c(1,1,2,2), ncol=2, bty='n', x.intersp=0.5, pch=c(1,2,1,2), inset=0.02)

# use position data of previous legend to draw legend with invisble lines and points but with labels and box. x.intersp controls distance between lines and labels
legend(x = L$rect$left, y = L$rect$top, legend = c('Group A', 'Group B'), col=rep(NA,2), lty=c(1,1), ncol=1, x.intersp = 3, bg = NA)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述