rename_with_counts(pima_diabetes, weight_class)
# Below is an example of how `rename_with_counts` can be helpful when
# creating plots and tables. This graph shows the outcomes of different
# weight classes in `pima_diabetes`. With the added information from
# `rename_with_counts`, we can see how common each category is.
library(ggplot2)
rename_with_counts(pima_diabetes, weight_class) %>%
ggplot(aes(x = reorder(weight_class, diabetes, function(x) mean(x == "Y")),
fill = diabetes)) +
geom_bar(position = "fill") +
coord_flip()
Run the code above in your browser using DataLab