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

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jun Shen-3
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add error bars to a line xyplot (lattice package)

Jim Lemon-4
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 <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add error bars to a line xyplot (lattice package)

William Revelle
In reply to this post by Jun Shen-3
You might want to look at the examples in error.bars.by  in the psych package.

Bill

> On Jan 26, 2015, at 7:58 PM, Jun Shen <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.
>

William Revelle           http://personality-project.org/revelle.html
Professor           http://personality-project.org
Department of Psychology   http://www.wcas.northwestern.edu/psych/
Northwestern University   http://www.northwestern.edu/
Use R for psychology             http://personality-project.org/r
It is 3 minutes to midnight   http://www.thebulletin.org

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add error bars to a line xyplot (lattice package)

Kevin Wright-5
In reply to this post by Jun Shen-3
See segplot in the latticeExtra package.

Kevin

On Mon, Jan 26, 2015 at 7:58 PM, Jun Shen <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.



--
Kevin Wright

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add error bars to a line xyplot (lattice package)

Bert Gunter
Well, the OP already referred to segplot.

But, see, he shouldn't be doing this plot in the first place. Yes, I
know it's fairly standard in science, but it's a bad idea (as are many
others, like the infamous "dynamite plot"). If uncertainty intervals
are desired, they should be model based, obtained,e.g. by the relevant
predict() method.

But this is OT for here, so I won't rant further.

Cheers,
Bert

Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll




On Tue, Jan 27, 2015 at 2:56 PM, Kevin Wright <[hidden email]> wrote:

> See segplot in the latticeExtra package.
>
> Kevin
>
> On Mon, Jan 26, 2015 at 7:58 PM, Jun Shen <[hidden email]> 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]]
>>
>> ______________________________________________
>> [hidden email] 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.
>
>
>
> --
> Kevin Wright
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to add error bars to a line xyplot (lattice package)

Kevin Wright-5
Doh, can't believe I missed that.  Sorry Bert.

On Tue, Jan 27, 2015 at 5:08 PM, Bert Gunter <[hidden email]> wrote:

> Well, the OP already referred to segplot.
>
> But, see, he shouldn't be doing this plot in the first place. Yes, I
> know it's fairly standard in science, but it's a bad idea (as are many
> others, like the infamous "dynamite plot"). If uncertainty intervals
> are desired, they should be model based, obtained,e.g. by the relevant
> predict() method.
>
> But this is OT for here, so I won't rant further.
>
> Cheers,
> Bert
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Clifford Stoll
>
>
>
>
> On Tue, Jan 27, 2015 at 2:56 PM, Kevin Wright <[hidden email]> wrote:
>> See segplot in the latticeExtra package.
>>
>> Kevin
>>
>> On Mon, Jan 26, 2015 at 7:58 PM, Jun Shen <[hidden email]> 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]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>>
>>
>> --
>> Kevin Wright
>>
>> ______________________________________________
>> [hidden email] 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.



--
Kevin Wright

______________________________________________
[hidden email] 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.