如何制作具有两列的R图例?
我想在我的图形上做一个图例,它是由如何制作具有两列的R图例?,r,plot,legend,R,Plot,Legend,我想在我的图形上做一个图例,它是由plot()函数生成的。原始的legend()函数将生成一个只有一列的列表。如何制作一个有两列的图例 检查以下内容: library(lattice) myPCH <- 15:17 Data <- rnorm(50) Index <- seq(length(Data)) xyplot(Data ~ Index, pch = myPCH, col=1:2, key = list(space = "right",
plot()
函数生成的。原始的legend()
函数将生成一个只有一列的列表。如何制作一个有两列的图例
检查以下内容:
library(lattice)
myPCH <- 15:17
Data <- rnorm(50)
Index <- seq(length(Data))
xyplot(Data ~ Index,
pch = myPCH, col=1:2,
key = list(space = "right", adj=1,
text = list(c("a", "b", "c"), cex=1.5),
points = list(pch = myPCH),
points = list(pch = myPCH,col=2)))
库(晶格)
myPCH对于标准绘图,我无法在一次调用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)
ncol=2
在legend
中,但我每个只需要一个文本标签row@FelixChan每行一个文本标签请包含一个可复制的示例,并更清楚地描述所需图例的外观。@BenBarnes图例实际上与我在上面绘制的图像相似。有两条不同的线,但使用相同的标签。你可以认为实线实际上是结果,虚线是预期的结果,但它们代表的是同一事物。我认为OP要求2x2行+2x1字符串。@ Pascal编辑了答案。