如何用2列制作R图例? [英] How to make R legend with 2 columns?

查看:104
本文介绍了如何用2列制作R图例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to make a legend on my graph, which is generated by plot() function. The original legend() function will generate a list which has only 1 column. How can I make a legend which has 2 columns?

推荐答案

在标准图的一次调用legend的过程中,我找不到一种解决方法.

I could not find a way to do that within a single call to legend for standard plots.

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

Here's an option, drawing two separate legends: one with lines and points, one with labels. x.intersp can be used to tweak distance between labels and lines.

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)

这篇关于如何用2列制作R图例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆