# NOT RUN {
library(dplyr)
library(ggplot2)
library(tidyr)
library(stringr)
# Data wrangling
masculinity_tidy <- masculinity_survey %>%
# Narrow down rows to those pertaining to first question of survey:
filter(question == 'In general, how masculine or "manly" do you feel?') %>%
# Eliminate columns not relating to sexual orientaiton:
select(-c(age_18_34, age_35_64, age_65_over, white_yes, white_no, children_yes,
children_no, overall)) %>%
# Convert data frame to tidy data (long) format:
pivot_longer(-c(question, response), names_to = "sexuality", values_to = "ratio_by_sexuality")
# Visualize results
ggplot(data = masculinity_tidy, aes(x = response, y = ratio_by_sexuality, fill = sexuality)) +
geom_bar(stat="identity", position = 'dodge') +
labs(x = "Response", y = "Proportion", labs = "Sexuality",
title = "In general, how masculine or 'manly' do you feel?")
# }
Run the code above in your browser using DataLab