Bar plot with error bars

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

Bar plot with error bars

Katherine Jones
Apologies if this has been asked before. I am having trouble  
understanding the R mailing list never mind R!

I am relatively new to R having migrated from Minitab and SPSS. I  
have managed to do some more complicated statistics such as  
hierarchical partitioning of variance on an 80,000 record dataset but  
have to admit that drawing a simple bar plot I could do by hand is  
proving extremely difficult!

I have Crawley's 'The R book' which is proving  a big help, but still  
does not provide me with all of the information I need.

What I want to do:-
I have a small dataset, with 'rate' as the dependent variable (y axis  
variable) and two groups ('cat' and 'box') which I have calculated  
the mean and standard error for and would like to display as a bar  
plot. I would like to display the standard error for each group NOT a  
pooled standard error (i.e. error bars will be different heights on  
the two bars). In the Crawley book, he just repeats the same error  
bars across all groups, and I don't know how to specify the different  
error for each bar.

What I have managed to do so far:-
-calculate mean and standard error
-plots means with confidence intervals
-plot means as bar plot but with no error bars or confidence intervals
-everything except what I want to do!

I have learnt a lot about R but it is getting rather frustrating that  
I can do complex GLMs but cannot do a simple plot in 4 hours! I have  
migrated to R because I like the way it can do almost anything and  
because I'm trying to go almost completely freeware as everytime I  
move institution I run into trouble with getting software licenses  
which also tend to be expensive. However, I'm not the most computer  
literate person and have grown up with 'menus' and 'windows'.

Any help much appreciated as it will save me much time and frustration!

Dr. Katherine Jones
Department of Biology,
Carleton University

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bar plot with error bars

Daniel Nordlund
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf
> Of Katherine Jones
> Sent: Monday, October 22, 2007 2:04 PM
> To: [hidden email]
> Subject: [R] Bar plot with error bars
>
> Apologies if this has been asked before. I am having trouble
> understanding the R mailing list never mind R!
>
> I am relatively new to R having migrated from Minitab and SPSS. I
> have managed to do some more complicated statistics such as
> hierarchical partitioning of variance on an 80,000 record dataset but
> have to admit that drawing a simple bar plot I could do by hand is
> proving extremely difficult!
>
> I have Crawley's 'The R book' which is proving  a big help, but still
> does not provide me with all of the information I need.
>
> What I want to do:-
> I have a small dataset, with 'rate' as the dependent variable (y axis
> variable) and two groups ('cat' and 'box') which I have calculated
> the mean and standard error for and would like to display as a bar
> plot. I would like to display the standard error for each group NOT a
> pooled standard error (i.e. error bars will be different heights on
> the two bars). In the Crawley book, he just repeats the same error
> bars across all groups, and I don't know how to specify the different
> error for each bar.
>
> What I have managed to do so far:-
> -calculate mean and standard error
> -plots means with confidence intervals
> -plot means as bar plot but with no error bars or confidence intervals
> -everything except what I want to do!
>
> I have learnt a lot about R but it is getting rather frustrating that
> I can do complex GLMs but cannot do a simple plot in 4 hours! I have
> migrated to R because I like the way it can do almost anything and
> because I'm trying to go almost completely freeware as everytime I
> move institution I run into trouble with getting software licenses
> which also tend to be expensive. However, I'm not the most computer
> literate person and have grown up with 'menus' and 'windows'.
>
> Any help much appreciated as it will save me much time and frustration!
>
> Dr. Katherine Jones
> Department of Biology,
> Carleton University
>

Katherine,

You might take a look at the R Graph Gallery, specifically graph 54 by Marc Schwartz.  The code for the plot is there, which you should be able to modify.

The url is http://addictedtor.free.fr/graphiques/ .  You can click on browse, and page down to the graph.

Hope this helpful,

Dan

Daniel Nordlund
Bothell, WA  USA

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bar plot with error bars

Manuel Morales
In reply to this post by Katherine Jones
Hi Katherine,

If you have the original data, you can use the function barplot.CI from
the package sciplot which will calculate the means and CI's for you.
Examples are at: http://mutualism.williams.edu/sciplot

If you have the means and CI's already calculated, the following
function will do what you want:

CI.plot <- function(mean, std, ylim=c(0, max(CI.H)), ...) {
    CI.H <- mean+1.96*std # Calculate upper CI
    CI.L <- mean-1.96*std # Calculate lower CI
    xvals <- barplot(mean, ylim=ylim, ...) # Plot bars
    arrows(xvals, mean, xvals, CI.H, angle=90) # Draw error bars
    arrows(xvals, mean, xvals, CI.L, angle=90)
}

On Mon, 2007-10-22 at 17:03 -0400, Katherine Jones wrote:

> Apologies if this has been asked before. I am having trouble  
> understanding the R mailing list never mind R!
>
> I am relatively new to R having migrated from Minitab nd SPSS. I  
> have managed to do some more complicated statistics such as  
> hierarchical partitioning of variance on an 80,000 record dataset but  
> have to admit that drawing a simple bar plot I could do by hand is  
> proving extremely difficult!
>
> I have Crawley's 'The R book' which is proving  a big help, but still  
> does not provide me with all of the information I need.
>
> What I want to do:-
> I have a small dataset, with 'rate' as the dependent variable (y axis  
> variable) and two groups ('cat' and 'box') which I have calculated  
> the mean and standard error for and would like to display as a bar  
> plot. I would like to display the standard error for each group NOT a  
> pooled standard error (i.e. error bars will be different heights on  
> the two bars). In the Crawley book, he just repeats the same error  
> bars across all groups, and I don't know how to specify the different  
> error for each bar.
>
> What I have managed to do so far:-
> -calculate mean and standard error
> -plots means with confidence intervals
> -plot means as bar plot but with no error bars or confidence intervals
> -everything except what I want to do!
>
> I have learnt a lot about R but it is getting rather frustrating that  
> I can do complex GLMs but cannot do a simple plot in 4 hours! I have  
> migrated to R because I like the way it can do almost anything and  
> because I'm trying to go almost completely freeware as everytime I  
> move institution I run into trouble with getting software licenses  
> which also tend to be expensive. However, I'm not the most computer  
> literate person and have grown up with 'menus' and 'windows'.
>
> Any help much appreciated as it will save me much time and frustration!
>
> Dr. Katherine Jones
> Department of Biology,
> Carleton University
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained, reproducible code.
--
http://mutualism.williams.edu

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bar plot with error bars

John Kane-2
In reply to this post by Katherine Jones
library(gplots)
?barplot2

should give you what you want.


--- Katherine Jones <[hidden email]>
wrote:

> Apologies if this has been asked before. I am having
> trouble  
> understanding the R mailing list never mind R!
>
> I am relatively new to R having migrated from
> Minitab and SPSS. I  
> have managed to do some more complicated statistics
> such as  
> hierarchical partitioning of variance on an 80,000
> record dataset but  
> have to admit that drawing a simple bar plot I could
> do by hand is  
> proving extremely difficult!
>
> I have Crawley's 'The R book' which is proving  a
> big help, but still  
> does not provide me with all of the information I
> need.
>
> What I want to do:-
> I have a small dataset, with 'rate' as the dependent
> variable (y axis  
> variable) and two groups ('cat' and 'box') which I
> have calculated  
> the mean and standard error for and would like to
> display as a bar  
> plot. I would like to display the standard error for
> each group NOT a  
> pooled standard error (i.e. error bars will be
> different heights on  
> the two bars). In the Crawley book, he just repeats
> the same error  
> bars across all groups, and I don't know how to
> specify the different  
> error for each bar.
>
> What I have managed to do so far:-
> -calculate mean and standard error
> -plots means with confidence intervals
> -plot means as bar plot but with no error bars or
> confidence intervals
> -everything except what I want to do!
>
> I have learnt a lot about R but it is getting rather
> frustrating that  
> I can do complex GLMs but cannot do a simple plot in
> 4 hours! I have  
> migrated to R because I like the way it can do
> almost anything and  
> because I'm trying to go almost completely freeware
> as everytime I  
> move institution I run into trouble with getting
> software licenses  
> which also tend to be expensive. However, I'm not
> the most computer  
> literate person and have grown up with 'menus' and
> 'windows'.
>
> Any help much appreciated as it will save me much
> time and frustration!
>
> Dr. Katherine Jones
> Department of Biology,
> Carleton University
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained,
> reproducible code.
>

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Bar plot with error bars

John Kane-2
In reply to this post by Katherine Jones
library(gplots)
?barplot2

should give you what you want.


--- Katherine Jones <[hidden email]>
wrote:

> Apologies if this has been asked before. I am having
> trouble  
> understanding the R mailing list never mind R!
>
> I am relatively new to R having migrated from
> Minitab and SPSS. I  
> have managed to do some more complicated statistics
> such as  
> hierarchical partitioning of variance on an 80,000
> record dataset but  
> have to admit that drawing a simple bar plot I could
> do by hand is  
> proving extremely difficult!
>
> I have Crawley's 'The R book' which is proving  a
> big help, but still  
> does not provide me with all of the information I
> need.
>
> What I want to do:-
> I have a small dataset, with 'rate' as the dependent
> variable (y axis  
> variable) and two groups ('cat' and 'box') which I
> have calculated  
> the mean and standard error for and would like to
> display as a bar  
> plot. I would like to display the standard error for
> each group NOT a  
> pooled standard error (i.e. error bars will be
> different heights on  
> the two bars). In the Crawley book, he just repeats
> the same error  
> bars across all groups, and I don't know how to
> specify the different  
> error for each bar.
>
> What I have managed to do so far:-
> -calculate mean and standard error
> -plots means with confidence intervals
> -plot means as bar plot but with no error bars or
> confidence intervals
> -everything except what I want to do!
>
> I have learnt a lot about R but it is getting rather
> frustrating that  
> I can do complex GLMs but cannot do a simple plot in
> 4 hours! I have  
> migrated to R because I like the way it can do
> almost anything and  
> because I'm trying to go almost completely freeware
> as everytime I  
> move institution I run into trouble with getting
> software licenses  
> which also tend to be expensive. However, I'm not
> the most computer  
> literate person and have grown up with 'menus' and
> 'windows'.
>
> Any help much appreciated as it will save me much
> time and frustration!
>
> Dr. Katherine Jones
> Department of Biology,
> Carleton University
>
> ______________________________________________
> [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
> and provide commented, minimal, self-contained,
> reproducible code.
>

______________________________________________
[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
and provide commented, minimal, self-contained, reproducible code.