geom_bar with its non-"identity" statistic confuses novice users and
forces them to learn about the stat argument (and statistics in
general in the grammar of graphics) which greatly complicates a first
approach to ggplot.
I suggested this in the past (and I know it would break existing code)
but I think geom_bar should default to stat="identity". At least, this
should be the case when y is supplied, which would limit the backward
compatibility problem. The requirement for stat="bin" is reduced by
the existence of geom_histogram anyway.
What does a "barplot" mean to most people? To me it just means a graph
with vertical bars, not necessarily a histogram, hence my expectation
that y should be specified and give the height of the bars.
JiHO
---
http://maururu.net
https://github.com/hadley/ggplot2/issues/161 and here
https://github.com/hadley/ggplot2/issues/82
Basically:
* there are two types of bar charts and unfortunately we give them the
same name. It's equally valid to expect that geom_bar will produce
either of them
* Unless you can provide compelling evidence that one is much more
common that the other, or suggest better names for both, I'm unwilling
to change the current behaviour because I think it will cause just as
many problems (but in the other direction)
Hadley
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
Yeah, that's me again.
> * there are two types of bar charts and unfortunately we give them the
> same name. It's equally valid to expect that geom_bar will produce
> either of them
>
> * Unless you can provide compelling evidence that one is much more
> common that the other,
I cannot provide general, literature-based evidence but I can say that
every single student I've taught:
- uses geom_histogram rather than geom_bar when asked to "represent
the distribution of a piece of data"
- is puzzled by the behaviour of geom_bar when he/she first tries it
I know this for a fact because these are two necessary steps in the
labs they do with me.
I insist that the first question does not mention the word "histogram"
but just "distribution" (because I would also accept a density plot),
but histogram is what they naturally think of and when they search the
documentation for it, they find geom_histogram.
The second question is about the total abundance of several species in
a dataset in three different locations, so they are usually drawn
towards a bar chart with three bars of different colour per species
(Excel habits I guess). Which either throws an error when the don't
pre-compute the sum of abundances or works (but abusively IMHO -- see
previous email) when they do.
> or suggest better names for both, I'm unwilling
> to change the current behaviour because I think it will cause just as
> many problems (but in the other direction)
I don't think the names could be improved (certainly not
geom_histogram and I can't think of something else for geom_bar).
But an additional argument to keep those names but change the
behaviour might be that:
- barplot() in base R produces bars of specified height (i.e. as
geom_bar with stat="identity")
- hist() in base R produces a histogram
It would be good to have the opinion of a larger sample of people on
this matter. Thanks in advance,
JiHO
---
http://maururu.net
Just to back it up with numbers and context:
- question 1 comes in every "introduction to R" class that I do so
that's ~100-120 students these last 3 years.
- question 2 comes in a specific lab so that's more like ~40 students
over the same 3 years
These are MSc students, so usually with a fair background in
statistics. 60% of them were french, the rest came from EU mostly. Few
of them were native english speakers (but I taught in English). See
https://github.com/hadley/ggplot2/issues/161 about why this might be
important.
JiHO
---
http://maururu.net
I have never had a student ask me about this. I think it is a
cultural difference - in Europe a bar chart typically means one thing,
and in New Zealand/USA it typically means something else.
It's not that I think my interpretation is right, but that if we
change it now, it will break a lot of code that currently works, and
break many people's expectations about what a barchart should do.
Hadley
That's probably it. Too bad for me you are not European then.
Still, the fact that geom_bar and geom_histogram both exist and do the
exact same thing would advocate for a change in geom_bar, wouldn't it?
(not that I am desperately trying to win an argument or anything...)
Or maybe we could detect the current locale of the user and have
geom_bar do something different based on ... just kidding ;)
JiHO
---
http://maururu.net
I don't agree with your premise that geom_bar() and geom_histogram()
do the 'exact same thing'. This is a common misperception. Bar charts
are meant to visualize discrete distributions; a histogram is a crude
type of density estimator with (when correctly used) a fixed bandwidth
(i.e., binwidth) and a uniform kernel function. There's a good reason
why that little space between categories in a bar chart exists - it
signifies that the values are not meant to be interpreted on a
continuous numeric scale. Similarly, the adjacency of the bars in a
histogram is a subtle visual cue that the variable of interest is on a
continuous scale. What does a bar chart mean in Europe that does not
conform to this definition?
Dennis
In ggplot they do. That's what I meant:
library("ggplot2")
d <- data.frame(x=runif(20), y=runif(20), z=factor(round(runif(20, 0, 4))))
ggplot(d, aes(x=x)) + geom_bar()
ggplot(d, aes(x=x)) + geom_histogram()
ggplot(d, aes(x=z)) + geom_bar()
ggplot(d, aes(x=z)) + geom_histogram()
# and the problematic cases
ggplot(d, aes(x=x, y=y)) + geom_bar()
ggplot(d, aes(x=x, y=y)) + geom_bar(stat="identity")
ggplot(d, aes(x=z, y=y)) + geom_bar(colour="red") # not sure what is
done here...
ggplot(d, aes(x=z, y=y)) + geom_bar(stat="identity", colour="red")
> This is a common misperception. Bar charts
> are meant to visualize discrete distributions; a histogram is a crude
> type of density estimator with (when correctly used) a fixed bandwidth
> (i.e., binwidth) and a uniform kernel function. There's a good reason
> why that little space between categories in a bar chart exists - it
> signifies that the values are not meant to be interpreted on a
> continuous numeric scale. Similarly, the adjacency of the bars in a
> histogram is a subtle visual cue that the variable of interest is on a
> continuous scale.
In that case, geom_bar should only allow discrete x and
geom_histogram, continuous x. That would indeed make for a clean
separation between the two. But both would still use stat="bin" by
default.
> What does a bar chart mean in Europe that does not
> conform to this definition?
I wouldn't go as far as saying that this is the "European" definition
but the definition I most commonly see is purely geometric: a bar
chart is a char with bars on it (which start from 0 on well formed
ones). But these bars can be used to display the number of occurrences
of a category (i.e. a distribution) or just any, possibly continuous,
quantity. This is the way Excel does bar charts I think: it allows to
use bars in the same way points or a line would be used.
In this later case, I think that boxplots are almost always better
suited but some people insist on drawing bars, because it highlights
that the quantity rises from 0 or simply because it's customary. In a
recent paper the main authors insisted that I drew bars + error bars
for average + SD concentrations of chemical components, even though
that was a very crude representation of the variability (and the data
was far from normal so the meaning of the mean was dubious). But that
was what they usually saw in the journal they intended to publish in.
Again, I would not agree that this is the correct definition. Yours
appears much more solid. Mine is probably just an operational
derivative of the bar chart.
JiHO
---
http://maururu.net