为什么我的条形图中的 y 轴没有完全显示?

Why the y axis in my barplot doesn't show completely?

不知道怎么改代码才能让barPlot中的y轴显示完整?我希望它最多显示 10 个,因为我的数据点中有 9.2 个,但它最多只显示 8 个。知道这是怎么回事吗?

代码如下:

这是它显示的内容:

只需像更改 xlim

那样设置 ylim = c(0, 10)

默认情况下不会绘制组所在的轴,因此垂直条形图不会有 x 轴;水平不会有 y 轴。您当然可以添加它。使用 barplot 的 return 值:

par(mfrow = c(2, 1))
bp <- barplot(c(8, 5), width = .5, main = 'Feature Exploration', xlim = c(0,4), ylim = c(0, 10),
              ylab = 'Errors (%)', xlab = 'ML Models', col = c('gray27','orangered4'))

## this will draw the x-axis but at points 1, 2, 3, ... which is not
## where the centers of your bars are plotted; you get that info in bp
axis(1)

bp <- barplot(c(8, 5), width = .5, main = 'Feature Exploration', xlim = c(0,4), ylim = c(0, 10),
              ylab = 'Errors (%)', xlab = 'ML Models', col = c('gray27','orangered4'))

## so try again with a fancy axis, bp is a matrix containing the centers
## of the plotted bars
axis(1, at = bp, labels = c('Model1','Model2'), lwd = 0, lwd.ticks = 1, tcl = -.5)