Graphics Reference
In-Depth Information
With
geom_bar()
, the default behavior is to use
stat="bin"
, which counts up the number of
cases for each group (each xposition, in this example). In the graph we can see that there are
about 23,000 cases with an ideal cut.
In this example, the variable on the x-axis is discrete. If we use a continuous variable on the x-
axis, we'll get a histogram, as shown in
Figure 3-8
:
ggplot(diamonds, aes(x
=
carat))
+
geom_bar()
Figure 3-8. Bar graph of counts on a continuous axis, also known as a histogram
It turns out that in this case, the result is the same as if we had used
geom_histogram()
instead
of
geom_bar()
.
See Also
If, instead of having
ggplot()
count up the number of rows in each group, you have a column
You could also get the same graphical output by calculating the counts before sending the data
For more about histograms, see
Making a Basic Histogram
.