我不知道如何更改代码,以便barPlot中的y轴完全显示?我希望它显示为10,因为我的数据点数为9.2,但最多只显示8个。任何想法是什么黑客?
这是代码:
以下是它的内容:
答案 0 :(得分:1)
只需设置ylim = c(0, 10)
,就像更改xlim
默认情况下,无论是哪个轴都没有绘制,所以垂直条形图不会有x轴;水平不会有y轴。你当然可以添加它。使用barplot
的返回值:
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)