首页 > 解决方案 > 无法在箱线图中设置轴的间隔:RStudio

问题描述

我正在尝试从大型数据集中制作箱线图。由于间隔很大,箱线图看起来不太好。我想修复 y 轴的间隔,但它给了我错误。为了您的方便,我正在添加我的代码和图表

我的代码:

boxplot(POS$Profit.Amount~POS$BA.Node, xlab="Location",
        ylab = "Amount of Profit", main="Profit Per Location", col=colors, axis(2, seq(0,100,10)))

图: https ://i.stack.imgur.com/EFAAf.png

标签: r

解决方案


您可以在 boxplot 函数中结合使用 ylim 和 yaxp 选项来解决这个问题:

#create some random data
y=runif(500, 20, 80)

#plot
boxplot(y, xlab="Location",
        ylab = "Amount of Profit", 
        main="Profit Per Location", yaxp= c(0,100, 10), ylim=c(0,100))

上面的代码将限制设置为 0 和 100,而 yaxp 将在 0 和 100 之间创建 10 个分区。


推荐阅读