我有一个带负值的2个数据集,所以barplot
给我一个带有条形图的图表。如何将y轴的原点设置为负值,以获得条形图?
我有什么:
A <- c(-7.3, -2.17, 1.05)
B <- c(-3.69, -5.04, -0.746)
AB <- c(A, B)
barplot(AB, col = c("darkgray","darkgray","darkgray","lightgray","lightgray","lightgray"),#
names.arg=c("A1", "A2", "A3", "B1", "B2", "B3"))
legend("bottomright", legend = c("A", "B"), fill = c("darkgray", "lightgray"), horiz = T)
我想要的是什么:
答案 0 :(得分:1)
new <- abs(-8 - AB)
barplot(new, beside=TRUE, ylim=c(0, 12), yaxt="n",
col = c("darkgray","darkgray","darkgray","lightgray","lightgray","lightgray"),#
names.arg=c("A1", "A2", "A3", "B1", "B2", "B3"))
axis(2, seq(0, 12, 2), labels=seq(-8,4,2))
box(bty="l")
legend("topright", legend = c("A", "B"), fill = c("darkgray", "lightgray"), horiz = T)