Description Usage Arguments Value Examples
Convenience function for generating ggplot2 barplots from raw datasets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
df |
a data frame with raw data |
x |
variable to be displayed on the x axis. Must be a column name of df. Can be unquoted. |
fill |
variable that defines the fill of the bars. Must be a column name of df. Can be unquoted. |
wrap |
variable along which the data should be split in different panels. See ?ggplot2::facet_wrap and ?ggplot2::facet_grid for more information. Default is NULL, i.e. no wrap. |
raw |
if TRUE, the function returns the raw data, i.e. a data frame with cross-tabulated absolute and relative frequencies. |
text |
if TRUE (the default), absolute frequencies are displayed on the bars using geom_text. |
vjust_strip |
vertical adjustment of the text, if text = TRUE. Behaves differently for stacked and dodged barplots. Under the hood, vjust is part of the position_stacked() call in stacked barplots (default: .5, i.e. in the middle of each portion of the bar) and part of the geom_text() call in dodged barplots (-.5, i.e. slightly above each bar). |
cex |
size of the text displaying the absolute frequencies. |
cex_axes |
size of the axis labels, 18pt by default. To get the ggplot2 default values and customize with your own ggplot layers, just enter a non-numeric value. |
percent |
If TRUE (the default), the y axis displays proportions in percent format. Requires package "scales". If FALSE (or if "scales" is not installed), it is displayed as a fraction between 0 and 1. |
dodge |
If FALSE (the default), a stacked barplot if produced. If TRUE, qbarplot() returns a dodged barplot, i.e. the bars are displayed side-by-side. |
xlab |
x axis label. By default, identical to x. |
ylab |
y axis label. By default, "Relative Frequency". |
wrap100 |
If wrap != NULL and wrap100 = TRUE, percentages are calculated separately for each category. In other words, if wrap100 = TRUE, the bars sum up to 100 percent in each panel. If wrap100 = FALSE (the default), the percentages sum up to 100 across panels. For illustration, compare e.g. |
tibble |
If raw = TRUE and tibble = TRUE (the default), the raw data are returned as a tibble. Only works if the "tibble" package is installed. See ?tibble::tibble for more information. |
display0 |
If text = TRUE, display0 = TRUE (the default) prevents 0 values (if there are any) from being shown on the text display. |
angle |
Use this to rotate the x tick labels. |
hjust |
horizontal justification of x tick labels. |
vjust |
vertical justification of x tick labels. |
color |
color scheme to be used for the plot. Can be an ordinary palette (see ?palettes) or an RColorBrewer palette, see ?scale_fill_brewer for available palettes. Set to FALSE to get ggplot's default color scheme. |
rev.palette |
if a color palette is used, setting rev.palette to TRUE will reverse it. |
... |
Further arguments to be passed on to ggplot(). |
a ggplot2 barplot or, if raw = TRUE, a data frame with the cross-tabulated raw and relative frequencies.
1 2 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.