7

我试图以与 R 默认情况下隔离带边框的箱线图相同的方式获得隔离条形图的相同效果。换句话说,我希望出现在下面第一个图中的边框出现在第二个图中:

par(mfrow=c(2,1))

## boxplot on a formula:
boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
# *add* notches (somewhat funny here):
boxplot(count ~ spray, data = InsectSprays,
        notch = TRUE, add = TRUE, col = "blue")


require(grDevices) # for colours
tN <- table(Ni <- stats::rpois(100, lambda=5))
r <- barplot(tN, col=rainbow(20))
#- type = "h" plotting *is* 'bar'plot
lines(r, tN, type='h', col='red', lwd=2)
4

1 回答 1

15

您只需box()在条形图代码的末尾添加。

par(mfrow=c(2,1))
boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
boxplot(count ~ spray, data = InsectSprays,
        notch = TRUE, add = TRUE, col = "blue")
require(grDevices) # for colours
tN <- table(Ni <- stats::rpois(100, lambda=5))
r <- barplot(tN, col=rainbow(20))
box()
lines(r, tN, type='h', col='red', lwd=2)
于 2013-03-05T23:45:21.467 回答