plot_density {APCtools} | R Documentation |
Plot the density of one metric or categorical variable
Description
Create a density plot or a boxplot of one metric variable or a barplot of one categorical variable, based on a specific subset of the data.
Usage
plot_density(
dat,
y_var,
plot_type = "density",
apc_range = NULL,
highlight_diagonals = NULL,
y_var_cat_breaks = NULL,
y_var_cat_labels = NULL,
weights_var = NULL,
log_scale = FALSE,
xlab = NULL,
ylab = NULL,
legend_title = NULL,
...
)
Arguments
dat |
Dataset with columns |
y_var |
Character name of the main variable to be plotted. |
plot_type |
One of |
apc_range |
Optional list with one or multiple elements with names
|
highlight_diagonals |
Optional internal parameter which is only
specified when |
y_var_cat_breaks |
Optional numeric vector of breaks to categorize
|
y_var_cat_labels |
Optional character vector for the names of the
categories that were defined based on |
weights_var |
Optional character name of a weights variable used to project the results in the sample to some population. |
log_scale |
Indicator if the main variable should be log10 transformed.
Only used if the |
xlab , ylab , legend_title |
Optional plot annotations. |
... |
Additional arguments passed to |
Details
If plot_density
is called internally from within
plot_densityMatrix
(i.e., if the dataset contains some of the
columns c("age_group","period_group","cohort_group")
), this function
will calculate the metric densities individually for these groups.
Value
ggplot object
Author(s)
Alexander Bauer alexander.bauer@stat.uni-muenchen.de, Maximilian Weigert maximilian.weigert@stat.uni-muenchen.de
Examples
library(APCtools)
data(travel)
plot_density(dat = travel, y_var = "mainTrip_distance")
plot_density(dat = travel, y_var = "mainTrip_distance")