A plotting question - how to get error bars?

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

A plotting question - how to get error bars?

toby-11
Dear R list,

Can anyone help with a plotting question? I'm trying to display some data
on a plot and I've almost got the format I need (see code below), but 2
things I can't get:

1. How to get "Jan","Feb","Mar" on the x=axis instead of 1:3?
2. How to get "T"s on the end of my error bars like you have in standard
scientific plots?

Any comments gratefully received!

Thanks,
Toby

xvals=1:3 #couldn't get it to be "Jan, Feb, Mar" on the x-axis
rgrT1=c(10,20,30)
errbarsT1lo=c(0.5830952,0.3741657,0.8944272)
errbarsT1up=errbarsT1lo
rgrT2=c(25,30,35)
errbarsT2lo=c(1.356466,3.535534,1.140175)
errbarsT2up=errbarsT2lo
minx=min(xvals);maxx=max(xvals)
miny=min(rgrT1-errbarsT1lo,rgrT2-errbarsT2lo);maxy=max(rgrT1+errbarsT1up,rgrT2+errbarsT2up)
plot(x=0,y=0,type="n",xlim=c(minx,maxx),ylim=c(miny,maxy),lab=c(2,20,0),bty="l",xlab="month",ylab="Relative
Growth Rate")
points(x=xvals,y=rgrT1,pch=21)
symbols(x=xvals,y=rgrT1,boxplots=cbind(0,0,errbarsT1lo,errbarsT1up,0.5),inches=FALSE,add=TRUE)
                #symbols does the error bars, but without the "T"s at the end. The
boxplot command does the Ts, but you can't have them without the box in
the middle (and you can't have different symbols for points either)
lines(x=xvals,y=rgrT1,lty=21)
points(x=xvals,y=rgrT2,pch=24)
symbols(x=xvals,y=rgrT2,boxplots=cbind(0,0,errbarsT2lo,errbarsT2up,0.5),inches=FALSE,add=TRUE)
lines(x=xvals,y=rgrT2,lty=24)
legend(x="right",c("Treatment 1","Treatment 2"),pch=c(21,24))

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: A plotting question - how to get error bars?

Sean Davis



On 3/27/06 6:55 AM, "[hidden email]" <[hidden email]> wrote:

> Dear R list,
>
> Can anyone help with a plotting question? I'm trying to display some data
> on a plot and I've almost got the format I need (see code below), but 2
> things I can't get:
>
> 1. How to get "Jan","Feb","Mar" on the x=axis instead of 1:3?

First, do your plot with (..., axes=F).  Then, look at the help for axis()
to put the axes on the plot.

> 2. How to get "T"s on the end of my error bars like you have in standard
> scientific plots?

RSiteSearch('error bars') several answers that might be of interest.

Sean

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

step() for glmmML

I.Szentirmai
In reply to this post by toby-11
Dear R Users,

I'm looking for a similar function as step() or drop1() for glmmML models,
but couldn't yet find any. I would appreciate if anyone could help me find
such a function.

Thanks,
Istvan


----- Original Message -----
From: <[hidden email]>
To: <[hidden email]>
Sent: Monday, March 27, 2006 1:55 PM
Subject: [R] A plotting question - how to get error bars?


> Dear R list,
>
> Can anyone help with a plotting question? I'm trying to display some data
> on a plot and I've almost got the format I need (see code below), but 2
> things I can't get:
>
> 1. How to get "Jan","Feb","Mar" on the x=axis instead of 1:3?
> 2. How to get "T"s on the end of my error bars like you have in standard
> scientific plots?
>
> Any comments gratefully received!
>
> Thanks,
> Toby
>
> xvals=1:3 #couldn't get it to be "Jan, Feb, Mar" on the x-axis
> rgrT1=c(10,20,30)
> errbarsT1lo=c(0.5830952,0.3741657,0.8944272)
> errbarsT1up=errbarsT1lo
> rgrT2=c(25,30,35)
> errbarsT2lo=c(1.356466,3.535534,1.140175)
> errbarsT2up=errbarsT2lo
> minx=min(xvals);maxx=max(xvals)
> miny=min(rgrT1-errbarsT1lo,rgrT2-errbarsT2lo);maxy=max(rgrT1+errbarsT1up,rgrT2+errbarsT2up)
> plot(x=0,y=0,type="n",xlim=c(minx,maxx),ylim=c(miny,maxy),lab=c(2,20,0),bty="l",xlab="month",ylab="Relative
> Growth Rate")
> points(x=xvals,y=rgrT1,pch=21)
> symbols(x=xvals,y=rgrT1,boxplots=cbind(0,0,errbarsT1lo,errbarsT1up,0.5),inches=FALSE,add=TRUE)
> #symbols does the error bars, but without the "T"s at the end. The
> boxplot command does the Ts, but you can't have them without the box in
> the middle (and you can't have different symbols for points either)
> lines(x=xvals,y=rgrT1,lty=21)
> points(x=xvals,y=rgrT2,pch=24)
> symbols(x=xvals,y=rgrT2,boxplots=cbind(0,0,errbarsT2lo,errbarsT2up,0.5),inches=FALSE,add=TRUE)
> lines(x=xvals,y=rgrT2,lty=24)
> legend(x="right",c("Treatment 1","Treatment 2"),pch=c(21,24))
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: A plotting question - how to get error bars?

Gabor Grothendieck
In reply to this post by Sean Davis
See plotCI in package gplots.

For dates you can make use of the builtin vector month.abb

plot(1:3, 11:13, xaxt = "n")
axis(1, 1:3, month.abb[1:3])

or use Date class:

xvals <- seq(as.Date("2006-01-01"), length = 3, by = "month")
plot(xvals, 1:3)

or with specific control over x axis:

xvals <- seq(as.Date("2006-01-01"), length = 3, by = "month")
plot(xvals, 1:3, xaxt = "n")
axis(1, xvals, format(xvals, "%b"))

More on dates is in the Help Desk article on R News 4/1.


As an aside, note that xlim=range(xvals) is a bit more compact..


On 3/27/06, Sean Davis <[hidden email]> wrote:

>
>
>
> On 3/27/06 6:55 AM, "[hidden email]" <[hidden email]> wrote:
>
> > Dear R list,
> >
> > Can anyone help with a plotting question? I'm trying to display some data
> > on a plot and I've almost got the format I need (see code below), but 2
> > things I can't get:
> >
> > 1. How to get "Jan","Feb","Mar" on the x=axis instead of 1:3?
>
> First, do your plot with (..., axes=F).  Then, look at the help for axis()
> to put the axes on the plot.
>
> > 2. How to get "T"s on the end of my error bars like you have in standard
> > scientific plots?
>
> RSiteSearch('error bars') several answers that might be of interest.
>
> Sean
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html