[R] How to use Lines function to draw the error bars?

Rui Barradas ruipbarradas at sapo.pt
Mon Oct 8 22:02:57 CEST 2012


Hello,

Do you want to use the lines function or do you want to draw error bars? 
The two are not the same, error bars are usualy drawn with function 
arrows(). The trick is in argument 'angle', set it to 90 degreesand have 
square arrow heads.

dat <- read.table(text="
  fit               lwr            upr
1  218.4332 90.51019 346.3561
2  218.3906 90.46133 346.3198
3  218.3906 90.46133 346.3198
4  161.3982 44.85702 277.9394
5  192.4450 68.39903 316.4909
6  179.8056 56.49540 303.1158
7  219.5406 91.52707 347.5542
8  162.6761 46.65760 278.6945
9  193.8506 70.59838 317.1029
10 181.3816 58.11305 304.6502
11 221.2871 92.14366 350.4305
12 164.2947 47.91081 280.6785
13 195.3415 72.04109 318.6418
14 182.7447 58.68660 306.8028
15 222.5223 91.86550 353.1791
", header = TRUE)
dat

ylm <- with(dat, range(range(fit), range(lwr), range(upr)))
plot(dat$fit, ylim = ylm, xlim = c(0, 16))
with(dat, arrows(1:15, fit, 1:15, lwr, angle = 90, length = 0.1))
with(dat, arrows(1:15, fit, 1:15, upr, angle = 90, length = 0.1))


Hope this helps,

Rui Barradas

Em 08-10-2012 20:11, liang.che at us.pwc.com escreveu:
>       fit               lwr            upr
> 1  218.4332 90.51019 346.3561
> 2  218.3906 90.46133 346.3198
> 3  218.3906 90.46133 346.3198
> 4  161.3982 44.85702 277.9394
> 5  192.4450 68.39903 316.4909
> 6  179.8056 56.49540 303.1158
> 7  219.5406 91.52707 347.5542
> 8  162.6761 46.65760 278.6945
> 9  193.8506 70.59838 317.1029
> 10 181.3816 58.11305 304.6502
> 11 221.2871 92.14366 350.4305
> 12 164.2947 47.91081 280.6785
> 13 195.3415 72.04109 318.6418
> 14 182.7447 58.68660 306.8028
> 15 222.5223 91.86550 353.1791
>
>
> I have tried
>
> new<-data.frame(newdata$Unemployment)
> prd<-predict.lm(fit,newdata,interval=c("confidence"),level=0.95)
> lines (new,prd[,3],col="red",lty=2)
>
> but it didn't give me anything.
>
> thanks
>
> ______________________________________________________________________
> The information transmitted, including any attachments, is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited, and all liability arising therefrom is disclaimed. If you received this in error, please contact the sender and delete the material from any computer. PricewaterhouseCoopers LLP is a Delaware limited liability partnership.  This communication may come from PricewaterhouseCoopers LLP or one of its subsidiaries.
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list