简体   繁体   English

如何更改小节的原点?

[英]How to change the origin of a barplot?

I have a 2 data set with negative values, so the barplot gives me a plot with bars down. 我有一个带有负值的2数据集,因此该小barplot我提供了一个条形向下的图。 How to set the origin of the y axis in a negative value, in order to obtain bars up? 如何将y轴的原点设置为负值,以便获得向上的条形?

What I have: 我有的:

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)

在此处输入图片说明

What I want: 我想要的是:

在此处输入图片说明

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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM