我想创建一个条形图并添加置信区间。我正在使用“箱线图+箭头”。但是,箱线图和箭头之间存在错误对齐。
我的数据集
$ 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
代码:
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')
结果:箱线图和箭头之间存在错误对齐。有谁知道错误?
我想要这个结果:
结果:箱线图和箭头之间存在错误对齐。有谁知道错误?