https://www.cnblogs.com/renping/p/7399830.html
博客:
6、R语言绘制带errorbar 的柱状图
转载:http://www.cnblogs.com/xudongliang/p/7283733.html
data <- data.frame(mean = c(10, 15), sd = c(12, 17))
rownames(data) <- c(“case”, “control”)
par(lwd = 2)
b <- barplot(data
m
e
a
n
,
n
a
m
e
s
.
a
r
g
=
r
o
w
n
a
m
e
s
(
d
a
t
a
)
,
c
o
l
=
c
(
"
r
e
d
"
,
"
b
l
u
e
"
)
,
y
l
i
m
=
c
(
0
,
25
)
,
a
x
e
s
=
F
,
f
o
n
t
=
2
)
a
r
r
o
w
s
(
b
[
1
]
,
d
a
t
a
mean, names.arg = rownames(data), col = c("red", "blue"), ylim = c(0, 25), axes = F, font = 2) arrows(b[1], data
mean,names.arg=rownames(data),col=c("red","blue"),ylim=c(0,25),axes=F,font=2)arrows(b[1],datamean[1], b[1], data
s
d
[
1
]
,
a
n
g
l
e
=
90
)
a
r
r
o
w
s
(
b
[
2
]
,
d
a
t
a
sd[1], angle = 90) arrows(b[2], data
sd[1],angle=90)arrows(b[2],datamean[2], b[2], data
s
d
[
2
]
,
a
n
g
l
e
=
90
)
l
i
n
e
s
(
x
=
c
(
b
[
1
]
,
b
[
1
]
,
b
[
2
]
,
b
[
2
]
)
,
y
=
c
(
d
a
t
a
sd[2], angle = 90) lines( x = c(b[1], b[1], b[2], b[2]), y = c( data
sd[2],angle=90)lines(x=c(b[1],b[1],b[2],b[2]),y=c(datasd[1] * 1.05 , data
s
d
[
2
]
∗
1.1
,
d
a
t
a
sd[2] * 1.1, data
sd[2]∗1.1,datasd[2] * 1.1, data
s
d
[
2
]
∗
1.05
)
,
l
t
y
=
2
)
t
e
x
t
(
x
=
b
[
1
]
+
(
b
[
2
]
−
b
[
1
]
)
/
2
,
y
=
d
a
t
a
sd[2] * 1.05), lty = 2) text( x = b[1] + (b[2] - b[1]) / 2, y = data
sd[2]∗1.05),lty=2)text(x=b[1]+(b[2]−b[1])/2,y=datasd[2] * 1.1, label = “****”, cex = 2, adj = c(0.5, 0))
axis(side = 2, lwd = 2, font = 2, cex = 1.5)