I would like to make a bar plot, where each bar is represented by one of the three columns in this data frame. The 'size' of each bar depends on the sum created by adorn_totals.
Reproducible example:
library(janitor)
test_df <- data.frame(
a = c(1:5),
b = c(1:5),
c = c(1:5)
) %>%
adorn_totals(where = 'row', tabyl = c(a, b, c))
I tried a solution that has previously been posted, but that didn't work: Link to the post: Bar plot for each column in a data frame in R
library(janitor)
library(ggplot2)
df <- data.frame(
a = c(1:5),
b = c(1:5),
c = c(1:5)
) %>%
adorn_totals(where = 'row', tabyl = c(a, b, c))
lapply(names(df), function(col) {
ggplot(df, aes(.data[[col]], ..count..)) +
geom_bar(aes(fill = .data[[col]]), position = "dodge")
}) -> list_plots