如何在R中围绕条形图绘制边框的方式与绘制边框的边框相同

Att*_*s29 6 plot r

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

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)
Run Code Online (Sandbox Code Playgroud)

ale*_*han 11

您只需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)
Run Code Online (Sandbox Code Playgroud)