titanic |>
plot_proportions(
Survived == "Yes",
overall_label = "All",
labels_color = "white"
)
titanic |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
fill = "lightblue"
)
# \donttest{
titanic |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
fill = "lightblue",
flip = TRUE
)
titanic |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
geom = "point",
color = "red",
size = 3,
show_labels = FALSE
)
titanic |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
geom = "area",
fill = "lightgreen",
show_overall = FALSE
)
titanic |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
geom = "line",
color = "purple",
ci_color = "darkblue",
show_overall = FALSE
)
titanic |>
plot_proportions(
Survived == "Yes",
by = -Survived,
mapping = ggplot2::aes(fill = variable),
color = "black",
show.legend = FALSE,
show_overall_line = TRUE,
show_pvalues = FALSE
)
# defining several proportions
titanic |>
plot_proportions(
dplyr::tibble(
Survived = Survived == "Yes",
Male = Sex == "Male"
),
by = c(Class),
mapping = ggplot2::aes(fill = condition)
)
titanic |>
plot_proportions(
dplyr::tibble(
Survived = Survived == "Yes",
Male = Sex == "Male"
),
by = c(Class),
mapping = ggplot2::aes(fill = condition),
free_scale = TRUE
)
iris |>
plot_proportions(
dplyr::tibble(
"Long sepal" = Sepal.Length > 6,
"Short petal" = Petal.Width < 1
),
by = Species,
fill = "palegreen"
)
iris |>
plot_proportions(
dplyr::tibble(
"Long sepal" = Sepal.Length > 6,
"Short petal" = Petal.Width < 1
),
by = Species,
fill = "palegreen",
flip = TRUE
)
# works with continuous by variables
iris |>
labelled::set_variable_labels(
Sepal.Length = "Length of the sepal"
) |>
plot_proportions(
Species == "versicolor",
by = dplyr::contains("leng"),
fill = "plum",
colour = "plum4"
)
# works with survey object
titanic |>
srvyr::as_survey() |>
plot_proportions(
Survived == "Yes",
by = c(Class, Sex),
fill = "darksalmon",
color = "black",
show_overall_line = TRUE,
labels_labeller = scales::label_percent(.1)
)
# }
# stratified analysis
titanic |>
plot_proportions(
(Survived == "Yes") |> stratified_by(Sex),
by = Class,
mapping = ggplot2::aes(fill = condition)
) +
ggplot2::theme(legend.position = "bottom") +
ggplot2::labs(fill = NULL)
# Convert Class into dummy variables
titanic |>
plot_proportions(
dummy_proportions(Class),
by = Sex,
mapping = ggplot2::aes(fill = level)
)
Run the code above in your browser using DataLab