When we talk about Republicans and Democrats, it’s important to remember just how many more people are unaffiliated, and how many more don’t even register. Yes, there are more Republicans than Democrats, but a well-organized campaign in specific areas can reach a lot of people and have a big sway on the total votes.
`summarise()` has grouped output by 'age'. You can override using the `.groups`
argument.
Code
party_order <-c("Libertarian", "Independent", "Republican", "Democrat")# Set the Party variable as a factor with the desired orderage_sum$party_affiliation <-factor(age_sum$party_affiliation, levels = party_order)f=ggplot(age_sum, aes(y=age,x=count,fill=party_affiliation,label=count)) +geom_col(position='dodge') +scale_fill_manual(values=c('Republican'='red','Democrat'='blue','Libertarian'='yellow','Unaffiliated'='purple'),na.value ='grey') +theme_minimal() +labs(x='Number of Voters',y='Age Range',title='Affiliation by Age Range',fill='Party Affiliation') +scale_x_continuous(labels = scales::comma)f %>% plotly::ggplotly()