plotting barplots with standard errors using R

ぐ巨炮叔叔 提交于 2019-12-29 01:58:30

问题


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


回答1:


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
  )
)


来源:https://stackoverflow.com/questions/9732720/plotting-barplots-with-standard-errors-using-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!