[R] How to add error bars to a line xyplot (lattice package)

Jim Lemon drjimlemon at gmail.com
Tue Jan 27 06:28:49 CET 2015


Hi Jun,
Here is one way to do this using the mtcars data set, although there
are probably better ways.

mtcars$sd<-runif(32,1,2)
mpgxhp<-xyplot(mpg~hp,mtcars,
 main="Miles per gallon by horsepower",
 xlab="Horsepower",ylab="Miles per gallon",
 panel=function(x,y,ulim,llim) {
  yspace<-diff(range(y))/100
  headlen<-par("pin")[1]/100
  panel.arrows(x,y+yspace,x,y+mtcars$sd,angle=90,length=headlen)
  panel.arrows(x,y-yspace,x,y-mtcars$sd,angle=90,length=headlen)
 panel.xyplot(x,y)
 }
)
print(mpgxhp)

Jim

On Tue, Jan 27, 2015 at 12:58 PM, Jun Shen <jun.shen.ut at gmail.com> wrote:
> Dear list,
>
> I have a couple of lines (superimposed) in an xyplot and just want to add
> error bars to each of the data point. It's been a while since this question
> was asked last time. But the segplot from latticeExtra is not straight
> forward. Just wonder if there is a better way to do this. Appreciate for
> any comment. Thanks.
>
> Jun
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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