Description Usage Arguments Value Figures Author(s) Examples
Plot the proportion of each combination of two predictors' levels having a specific outcome level and the 95% confidence interval of the proportion. Useful for assessing the presence/effects of an interaction between categorical predictors on an outcome.
1 2 | plot_prop2(data, predictor1, predictor2, outcome, ref_level,
ref_value = 0.5, add_n = FALSE, width = 0, flip = FALSE)
|
data |
The dataframe containing the predictor and outcome variables. |
predictor1 |
The first predictor variable name. This will be shown on the x-axis. |
predictor2 |
The second predictor variable name. This will be identified by color and shape in the legend. |
outcome |
The outcome variable name. |
ref_level |
A string providing the specific outcome level to show the proportions for. |
ref_value |
Defaults to 0.5. A numeric providing the proportion value of interest to compare to. |
add_n |
Defaults to TRUE. A logical indicating whether to add the total number of observations of each level to the plot. |
width |
Defaults to 0. A numeric providing the width of the error bars. |
flip |
Defaults to FALSE. A logical indicating whether to flip the plot. |
Returns a ggplot object with the first predictor levels on the x-axis and the proportion of values in the ref_level of the outcome on the y-axis. The second predictor variable is identified by shape and color in the legend.
Andrew Kostandy (andrew.kostandy@gmail.com)
1 2 3 4 5 | Titanic2 <- as.data.frame(Titanic)
Titanic2 <- Titanic2[rep(seq(1:nrow(Titanic2)), Titanic2$Freq), -5]
plot_prop2(Titanic2, Class, Sex, Survived, "Yes", ref_value = 0.323,
add_n = FALSE, width = 0, flip = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.