【问题标题】:Barbox with arrows带箭头的 Barbox
【发布时间】:2013-11-06 21:15:58
【问题描述】:

我想创建一个条形图并添加置信区间。我正在使用“箱线图+箭头”。但是,箱线图和箭头之间存在错误对齐。

我的数据集

$ df <- read.csv("database.csv", header=TRUE, sep=",")
$ df

# df is 'data frame'
# Gives mean and confidence interval (ci)

                   method      mean          ci
4                       A 0.3873552 0.002879887
6                       B 0.3873552 0.002879887
11                      C 0.3873552 0.002879887
12                      D 0.3873552 0.002879887
10                      E 0.3757940 0.005424378
1                       F 0.3715910 0.001226391
3                       G 0.3642126 0.010307811
5                       H 0.3615370 0.001347359
9                       I 0.3589878 0.002041493
13                      J 0.3585191 0.006083269
2                       K 0.3570351 0.002684985
7                       L 0.3497304 0.015632625
8                       M 0.2994054 0.001846430

R 代码:

result <- df

barplot(result$modularity, names=result$method, space = 0.3,  main = "Title", las=0.8, cex.names=0.8, ylab="y label", ylim = c(0.2,0.5),yaxp=c(0.2,0.5,10), xpd=F)

names = result$method
x = 1:13*2-1
CI.up = as.numeric(result$modularity)+as.numeric(result$ci)
CI.dn = as.numeric(result$modularity)-as.numeric(result$ci)
arrows(x,CI.dn,x,CI.up,code=3,length=0.06,angle=90,col='black')

结果:箱线图和箭头之间存在错误对齐。有人知道错误吗?

我想要这个结果:

结果:箱线图和箭头之间存在错误对齐。有人知道错误吗?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    barplot 不默认在整数 x 值上绘制条形图(不在 1、2、...上)。您可以通过设置x &lt;- barplot() 从条形图中获取 x 值。

    尝试以下方法:

    x <- barplot(result$modularity, ...)
    arrows(x,CI.dn,x,CI.up,code=3,length=0.06,angle=90,col='black')
    

    【讨论】:

    • @thelatemail:是的!我已经纠正了我在答案中的错误
    猜你喜欢
    • 2014-03-11
    • 2018-08-26
    • 2019-12-03
    • 2013-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-09
    • 1970-01-01
    相关资源
    最近更新 更多