我有一个柱状图,看起来像这样:

我想在加粗的矩形中的某个地方添加一个图例,我已经尝试了par(xpd=TRUE)和设置第四个条形图的边距,但由于某些原因,我无法让它工作…
所以如果你有任何想法,请让我知道!
发布于 2013-03-20 05:02:36
我不确定为什么xpd不能为您工作,但是下面这段代码应该会给您一些线索:
par(mfrow=c(2,2), xpd=TRUE)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
legend(-4.5, 56, c("A", "B"), col=2:3,lwd=1)为了了解图例的坐标,我使用了locator()函数。
发布于 2013-03-20 05:30:59
你可以在这里使用不同高度的layout

layout(rbind(c(1, 2),
c(3, 3),
c(4, 5)),
heights=c(3, 1.5, 3),
respect=FALSE)
tN <- table(Ni <- stats::rpois(100, lambda = 5))
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)
plot.new()
#box()
text(0.5,0.5,'legend in center',cex=3)
barplot(tN, col = 2:3)
barplot(tN, col = 2:3)发布于 2013-03-20 05:05:53
试试locator {graphics}
?locator
legend(locator(1), border=FALSE, fill=FALSE, "try the position") 在绘图()之后,您可以单击绘图窗口中所需的位置
https://stackoverflow.com/questions/15510228
复制相似问题