View source: R/plot_variable.R
plot_variable | R Documentation |
Plot the distribution of one variable in the data against age, period or
cohort. Creates a bar plot for categorical variables (see argument
geomBar_position
) and boxplots or a line plot of median values for
metric variables (see plot_type
).
plot_variable( dat, y_var, apc_dimension = "period", log_scale = FALSE, plot_type = "boxplot", geomBar_position = "fill", legend_title = NULL, ylab = NULL, ylim = NULL )
dat |
Dataset containing columns |
y_var |
Character name of the variable to plot. |
apc_dimension |
One of |
log_scale |
Indicator if the visualized variable should be log10 transformed. Only used if the variable is numeric. Defaults to FALSE. |
plot_type |
One of |
geomBar_position |
Value passed to |
legend_title |
Optional character title for the legend which is drawn for categorical variables. |
ylab, ylim |
Optional arguments for styling the ggplot. |
ggplot object
Alexander Bauer alexander.bauer@stat.uni-muenchen.de
library(APCtools) data(travel) # plot a metric variable plot_variable(dat = travel, y_var = "mainTrip_distance", apc_dimension = "period", log_scale = TRUE) plot_variable(dat = travel, y_var = "mainTrip_distance", apc_dimension = "period", log_scale = TRUE, plot_type = "line") # plot a categorical variable plot_variable(dat = travel, y_var = "household_size", apc_dimension = "period") plot_variable(dat = travel, y_var = "household_size", apc_dimension = "period", geomBar_position = "stack")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.