Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
529 views
in Technique[技术] by (71.8m points)

plot - plotting barplots with standard errors using R

I am trying to plot a simple barplot with standard errors and its driving me crazy. I did look up some examples and got as far as this:

rt5 <- data.frame(rtgrp=c(37.2,38.0,38.3,38.5,38.9),
mort=c(35,11,16,8,4),
se=c(0.08,0.01,0.005,0.01,0.02))
rt5
xvals=with(rt5,
barplot(mort,names.arg=rtgrp,
xlab="PTEMP_R group mean",ylab="%",ylim=c(0,max(mort+10+se))))

I am trying to get through the last line of script but have been on it for quite a while:

with(rt5,
arrows(xvals,mort,xvals,mort+se,length=45,angle=90,code=3))

I would really love to get over this one!

Thanks,

Baz

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

length is the size of the arrow (the width of the error bar): 45 is much, much larger than your plot. A smaller value should work.

with(rt5, 
  arrows(
    xvals,mort,xvals,mort+se, 
    length=.3, angle=90, code=3,
    # Change the colour and line width, to see the error bars
    col="navy", lwd=5
  )
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...