[R] Plotting confidence intervals

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Sun Dec 8 11:00:49 CET 2019


Hi Philip,
This may be a starter:

attach(airquality)
heights <- tapply(Temp,Month,mean)
temp_sd<-tapply(Temp,Month,sd)
lower <- tapply(Temp,Month,function(v) t.test(v)$conf.int[1])
upper <- tapply(Temp,Month,function(v) t.test(v)$conf.int[2])
library(plotrix)
barp(heights,ylim=c(0,100),names.arg=month.abb[5:9],
 main="Air quality (May-Sep)",xlab="Month",ylab="Temperature")
dispersion(1:5,y=heights,ulim=upper,llim=lower,intervals=FALSE)
ci95<-seq(-1.96,1.96,length.out=40)
norm_curve<-rescale(dnorm(ci95),c(0,0.4))
for(i in 1:5)
 polygon(c(i-norm_curve,i+norm_curve),
  c(heights[i]+ci95*temp_sd[i],heights[i]+rev(ci95*temp_sd[i])))

Jim

On Sun, Dec 8, 2019 at 8:18 PM <phil using philipsmith.ca> wrote:
> >> I want to show little bell curves on my bar chart to illustrate the
> >> confidence ranges. The following example from Paul Teetor's "R
> >> Cookbook"
> >> does what I want, but shows I-beams instead of bell curves. The
> >> I-beams
> >> suggest uniform, rather than normal distributions. So I am looking
> >> for a
> >> way to plot normal distribution curves instead.



More information about the R-help mailing list