Re: [R] error bars for a barchart

2012-05-02 Thread Beatriz De Francisco
Walmes, Thank you so much!!!
I am still trying to understand all of your code but it works. I have changed 
it a bit so that I get upper and lower limits for the error bar, and that the 
origin starts at 0 so the negative values are plotted correctly.

barchart(Change~fTreat,groups=Process,change,
 stderr=change$stderr,
 ylab="Pocertage change",
 xlab="Treatment",
 #ylim=-115:50,
 scales=list(alternating=FALSE,
 tick.number=7,
 tck=c(-1,0)),
 prepanel=function(y, stderr, subscripts=subscripts, ...){
   uy <- as.numeric(y+stderr[subscripts])
   ly <- as.numeric(y-stderr[subscripts])
   list(ylim=range(y,uy,ly, finite=TRUE))
 },
 panel=
   function(x, y, subscripts, groups, stderr, box.ratio, ...){
 panel.barchart(x, y, subscripts=subscripts,
groups=groups, box.ratio=box.ratio,origin=0, ...)
 panel.abline(h=0,col="black",...)
 d <- 1/(nlevels(groups)+nlevels(groups)/box.ratio)
 g <- (as.numeric(groups[subscripts])-1); g <- (g-median(g))*d
 panel.arrows(as.numeric(x)+g,y-stderr[subscripts], 
as.numeric(x)+g, y+stderr[subscripts],
  code=3,angle=90, length=0.025)
   }
 )
I am very new to creating function and would be great if you could explain what 
the d and g elemens actually do?
this is just for me to understand and later maybe make my own functions. I am 
assuming that g centers the error bars? but d?

Regards

Beatriz de Francisco Mora
PhD Student
The Scottish Association for Marine Science
Scottish Marine Institute
Oban
PA37 1QA
Tel: 06131 559000 (switchboard)
Fax: 01631559001
E. beatriz.defranci...@sams.ac.uk
http://www.smi.ac.uk/beatriz-de-franciso

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of 
ilai [ke...@math.montana.edu]
Sent: 02 May 2012 04:14
To: Walmes Zeviani
Cc: r-help@r-project.org
Subject: Re: [R] error bars for a barchart

Thank you for your example. I only skimmed it, but since both
solutions use nlevels and box.ratio it is no surprise we end up at the
same place (although I do think your g-median is nicer than my 3/4).

Thing is, I wouldn't call either of these "simple"... would be nice if
one could just query the "new" centers, but I don't know if there is a
way without hacking panel.barchart itself ?

Cheers

On Tue, May 1, 2012 at 1:34 PM, Walmes Zeviani  wrote:
> I have a repoducibe example here
>
> http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/
>
> Sorry for it be in Portuguese.
>
> Walmes.
>
> ==
> Walmes Marques Zeviani
> LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)
> Departamento de Estatística - Universidade Federal do Paraná
> fone: (+55) 41 3361 3573
> VoIP: (3361 3600) 1053 1173
> e-mail: wal...@ufpr.br
> twitter: @walmeszeviani
> homepage: http://www.leg.ufpr.br/~walmes
> linux user number: 531218
> ==

__
R-help@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.
The Scottish Association for Marine Science (SAMS) is registered in Scotland as 
a Company Limited by Guarantee (SC009292) and is a registered charity (9206). 
SAMS has an actively trading wholly owned subsidiary company: SAMS Research 
Services Ltd a Limited Company (SC224404). All Companies in the group are 
registered in Scotland and share a registered office at Scottish Marine 
Institute, Oban Argyll PA37 1QA. The content of this message may contain 
personal views which are not the views of SAMS unless specifically stated. 
Please note that all email traffic is monitored for purposes of security and 
spam filtering. As such individual emails may be examined in more detail.

__
R-help@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.


Re: [R] error bars for a barchart

2012-05-01 Thread ilai
Thank you for your example. I only skimmed it, but since both
solutions use nlevels and box.ratio it is no surprise we end up at the
same place (although I do think your g-median is nicer than my 3/4).

Thing is, I wouldn't call either of these "simple"... would be nice if
one could just query the "new" centers, but I don't know if there is a
way without hacking panel.barchart itself ?

Cheers

On Tue, May 1, 2012 at 1:34 PM, Walmes Zeviani  wrote:
> I have a repoducibe example here
>
> http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/
>
> Sorry for it be in Portuguese.
>
> Walmes.
>
> ==
> Walmes Marques Zeviani
> LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)
> Departamento de Estatística - Universidade Federal do Paraná
> fone: (+55) 41 3361 3573
> VoIP: (3361 3600) 1053 1173
> e-mail: wal...@ufpr.br
> twitter: @walmeszeviani
> homepage: http://www.leg.ufpr.br/~walmes
> linux user number: 531218
> ==

__
R-help@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.


Re: [R] error bars for a barchart

2012-05-01 Thread Walmes Zeviani
I have a repoducibe example here

http://ridiculas.wordpress.com/2011/11/23/media-e-desvio-padrao-de-muitas-variaveis-separado-por-grupos/

Sorry for it be in Portuguese.

Walmes.

==
Walmes Marques Zeviani
LEG (Laboratório de Estatística e Geoinformação, 25.450418 S, 49.231759 W)
Departamento de Estatística - Universidade Federal do Paraná
fone: (+55) 41 3361 3573
VoIP: (3361 3600) 1053 1173
e-mail: wal...@ufpr.br
twitter: @walmeszeviani
homepage: http://www.leg.ufpr.br/~walmes
linux user number: 531218
==

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] error bars for a barchart

2012-05-01 Thread ilai
Hi,
I think the issue is not "respecting the groups" but finding the
x-location of the center of bars in panel.barchart(groups,...). Don't
know about the memisc package, but doesn't look like it provides an
easy solution. This is how I do it:
http://www.mail-archive.com/r-help@r-project.org/msg162299.html

Might need to modify some for your data.

HTH

On Tue, May 1, 2012 at 8:01 AM, Beatriz De Francisco
 wrote:
> Hi
> I have the following barchart to which I want to add error bars.
>
>    library(lattice)
>    barchart(Change~fTreat,groups=Process,change,
>              auto.key=list(points=FALSE,rectangles=TRUE),
>              panel=function(x, y,...){
>                panel.barchart(x,y,origin = 0,...);
>                panel.abline(h=0,col="black",...);
>                }
>              )
>
> I have tried using the panel.errbars from the memisc package which works 
> great for xyplots, but when I add it to my code it does not respect the 
> groups.
>
>    library(memisc)
>    barchart(cbind(Change,lower,upper)~fTreat,groups=Process,change,
>         ylab="Pocertage change",
>         ylim=-115:50,
>         scales=list(alternating=FALSE,
>                     tick.number=7,
>                     tck=c(-1,0)),
>         panel=function(x, y,groups,...){
>           panel.barchart(x,y=change$Change,groups=change$Process,origin = 
> 0,...);
>           panel.abline(h=0,col="black",...);
>           panel.errbars(x,y,make.grid="none",ewidth=0.2,type="n",...)
>         }
>         )
>
> Any ideas of how to add error bars to my plot either using the panel.errbars 
> or any other function?
>
> The data:
>
>        structure(list(Treat = structure(c(3L, 4L, 1L, 2L, 3L, 4L, 1L,
>    2L), .Label = c("12-380", "12-750", "8-380", "8-750"), class = "factor"),
>        Process = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = 
> c("Resp",
>        "Cal"), class = c("ordered", "factor")), Change = c(-33.05,
>        -34.74, 20.94, 18.06, 6.85, -28.57, -8.1, -78.72), upper = 
> c(-13.22896628,
>        -28.61149669, 31.29930461, 27.30173776, 39.73271282, 9.458372948,
>        13.11035572, -47.03745704), lower = c(-52.86120694, -40.87446411,
>        10.57421563, 8.822042178, -26.03144161, -66.60447035, -29.30563327,
>        -110.3973761), fTreat = structure(c(1L, 2L, 3L, 4L, 1L, 2L,
>        3L, 4L), .Label = c("8-380", "8-750", "12-380", "12-750"), class = 
> c("ordered",
>        "factor"))), .Names = c("Treat", "Process", "Change", "upper",
>    "lower", "fTreat"), row.names = c(NA, -8L), class = "data.frame")
>
> Regards
>
> Beatriz de Francisco Mora
> PhD Student
> The Scottish Association for Marine Science
> Scottish Marine Institute
> Oban
> PA37 1QA
> Tel: 06131 559000 (switchboard)
> Fax: 01631559001
> E. beatriz.defranci...@sams.ac.uk
> http://www.smi.ac.uk/beatriz-de-franciso
>
> The Scottish Association for Marine Science (SAMS) is registered in Scotland 
> as a Company Limited by Guarantee (SC009292) and is a registered charity 
> (9206). SAMS has an actively trading wholly owned subsidiary company: SAMS 
> Research Services Ltd a Limited Company (SC224404). All Companies in the 
> group are registered in Scotland and share a registered office at Scottish 
> Marine Institute, Oban Argyll PA37 1QA. The content of this message may 
> contain personal views which are not the views of SAMS unless specifically 
> stated. Please note that all email traffic is monitored for purposes of 
> security and spam filtering. As such individual emails may be examined in 
> more detail.
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.