[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-devel
Subject:    Re: [Rd] Suggestion: barplot function
From:       Marc Schwartz <marc_schwartz () me ! com>
Date:       2017-01-27 15:27:43
Message-ID: CA798A7B-B6C5-407B-9F1D-72CD080CE2C7 () me ! com
[Download RAW message or body]


> On Jan 27, 2017, at 8:30 AM, danielrenato@lycos.com wrote:
> 
> Hello developers folks!
> 
> First, congratulations for the wonderful work with R.
> 
> For science, barplots with error bars are very important. We were wondering that is \
> so easy to use the boxplot function: 
> boxplot(Spores~treatment, col=treatment_colors)
> 
> But there is no such function for barplots with standard deviation or standard \
> error. It becomes a "journey" to plot a simple graph (e.g. \
> https://www.r-bloggers.com/building-barplots-with-error-bars/). 
> The same way that is easy to use the boxplot function, do you think it is possible \
> to upgrade the barplot function: i.e.: barplot(Spores~treatment, \
> error.bar=standard_error, col=treatment_colors) 
> Thank you so much!
> Daniel, FU-Berlin


Hi,

With the caveat that I do not speak on behalf of R Core:

Boxplots are specifically designed to include "whiskers" (NOT error bars) that aid to \
visually describe the distribution of continuous data. The whiskers do not represent \
standard deviations (SDs). Thus, that the boxplot() function contains the code to \
draw the whiskers automatically is not relevant to barplot().

Barplots are best used to visually present tabulations of categorical data (e.g. \
counts or percentages), in which case, the "error" bars would typically represent \
binomial or similar confidence intervals. Even there, many will advocate that \
dotplots be used instead as a better presentation format, as barplots, much like pie \
charts, have a high "ink to data" ratio.

Barplots should not really be used to present continuous data (e.g. means and SDs).

You will find a great deal of disagreement with your premise that barplots with error \
bars are very important to science. If you do a Google search for "Dynamite Plot", \
especially where only the upper error bar is included, you will find a variety of \
critical discussions on that point, such as:

  http://biostat.mc.vanderbilt.edu/wiki/pub/Main/TatsukiRcode/Poster3.pdf \
<http://biostat.mc.vanderbilt.edu/wiki/pub/Main/TatsukiRcode/Poster3.pdf>

You pointed to one example of how easy it is to actually add error bars to a barplot \
in R, and that approach, of incrementally building plots using multiple functions, is \
an integral part of R's philosophy. There is also an example in ?barplot.

Generally, R's default approaches to most analyses are extremely well reasoned. Thus, \
if you don't see something in a function by default, there is generally strong logic \
behind what is being done, or as in this case, not being done.

If you wanted to, it would be a reasonable exercise for you to create your own \
plotting function that wraps barplot() and either segments() or arrows() in a single \
function call, where you can pass arguments that contain the values for the various \
components and draw the plot as you desire. That is how a lot of R code is created.

There are other graphic functions in R packages, such as ggplot2 \
(https://www.r-bloggers.com/using-r-barplot-with-ggplot2/ \
<https://www.r-bloggers.com/using-r-barplot-with-ggplot2/>) and others on CRAN that \
offer methods to add error bars to barplots that others have created if you wanted to \
research those.

As a result of all of the above, I am not sure that, after all these years, error \
bars would be added to barplot() as a standard feature.

Regards,

Marc Schwartz


	[[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic