geom_histogram
Plot the distribution of a single continuous variable
by dividing the x axis into bins and counting the number
of observations in each bin.
Aesthetics
Other Properties
binwidth |
The width of the bins. Can be specified as a numeric value, or a function that calculates width from x. The default is to use bins bins that cover the range of the data. You should always override this value, exploring multiple widths to find the best to illustrate the stories in your data. The bin width of a date variable is the number of days in each time; the bin width of a time variable is the number of seconds |
bins |
Number of bins. Overridden by binwidth. Defaults to 30 |
Computed Variables
count |
number of points in bin |
density |
density estimate |
ncount |
count, scaled to maximum of 1 |
ndensity |
density estimate, scaled to maximum of 1 |
Similar Geometries
geom_freqpoly,
geom_bar
Description and Details
Using the described geometry, you can create histogram in
your data visualization that is defined by a position aesthetic
property x. You can find this geometry in the ribbon toolbar
tab Layers, under the 1D button.
The histogram displays the number of cases occurrences on the
continuous x axis that are divided into defined intervals and
we display their absolute or relative counts (Computed variables).
To display a simple histogram, you need select a dataset and
map selected variable to the positional aesthetic property – x.
In the following example, we used a built-in diamonds dataset
and our histogram was based on the values of carat variables.
An important parameter that strongly influences the resulting
character of the histogram is the width of bins in which are
occurrences counted. Bins width can be defined by two properties,
namely binwidth and bins. Using the binwidth parameter, you can
define the width of each bin along the x-axis.
Conversely, if you define the bins parameter (numeric value –
30 bins by default), you define the number of bins along
the x-axis. If you define both, program will use the binwidth.
The individual histogram bars you can divide using another
categorical variable by mapping these categories to the fill
aesthetic property. The example is shown in the following figure.
Finally, more options you have if you will use the geom_histogram
with other objects, such as facet_wrap, which allow you to wrap
one plot into multiple, based on the selected categorical
variable. The following example shows a histogram of carat
values that are broken down by diamonds quality (fill aesthetics)
and diamonds color (faceting).
Similar to the geom_histogram is defined also the geom_freqpoly
layer, but it shows the result as a frequency line.