【问题标题】:How to draw a border around a barplot in R the same way a border is drawn for a boxplot如何在 R 中的条形图周围绘制边框,就像为箱线图绘制边框一样
【发布时间】:2013-03-05 23:31:20
【问题描述】:

我正在尝试以与 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)

【问题讨论】:

    标签: r plot


    【解决方案1】:

    您只需在条形图代码的末尾添加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)
    

    【讨论】:

    • 谢谢!那很完美。你是怎么知道/发现的?
    • 好吧,我只是记得使用它,但刚刚检查过,当用谷歌搜索“在 barplot r 周围添加框”时的顶部链接给出了答案!
    • 谢谢 - 但有谁知道为什么 bty 参数首先不适用于 boxplot
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多