library(ggplot2)
library(dplyr)
# Conditional probabilities of response for each race/ethnicity
race_justice %>%
count(race_eth, response) %>%
group_by(race_eth) %>%
mutate(prop = n / sum(n))
# Stacked bar plot of counts
ggplot(race_justice, aes(x = race_eth, fill = response)) +
geom_bar() +
labs(
x = "Race / ethnicity",
y = "Count",
title = "Do you think Black and White people receive
equal treatment from the police?",
fill = "Response"
)
# Stacked bar plot of proportions
ggplot(race_justice, aes(x = race_eth, fill = response)) +
geom_bar(position = "fill") +
labs(
x = "Race / ethnicity",
y = "Proportion",
title = "Do you think Black and White people receive
equal treatment from the police?",
fill = "Response"
)
Run the code above in your browser using DataLab