【发布时间】:2013-03-08 18:16:11
【问题描述】:
我有一个条形图,如下所示:
我想在粗体矩形的某处添加一个图例,我已经尝试过 par(xpd=TRUE) 并为第四个条形图设置边距,但由于某些原因我无法让它工作......
如果你有任何想法,请告诉我!
【问题讨论】:
我有一个条形图,如下所示:
我想在粗体矩形的某处添加一个图例,我已经尝试过 par(xpd=TRUE) 并为第四个条形图设置边距,但由于某些原因我无法让它工作......
如果你有任何想法,请告诉我!
【问题讨论】:
你可以在这里使用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)
【讨论】:
试试locator {graphics}
?locator
legend(locator(1), border=FALSE, fill=FALSE, "try the position")
在你的 plot() 之后,你可以在你想要的位置点击你的绘图窗口
【讨论】:
不知道为什么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() 函数。
【讨论】: