I'm using an csv of survey data. Each row is an individual survey. One of the questions asked is "What activities do you take part in at the beach?". There is a column for each of the 12 activities listed. If an interviewer said they took part in an activity, the csv has a 1 and if they did not it has a 2. I want to create a barplot in ggplot2 showing how many people participate in all activities, and then use cross tabs (gender, location, age, etc.) for fill later on.
I've done this in base r:
barplot(act.all.13,xlab="Activity",ylab="NUmber of Responses",names.arg=" ",legend=c("Swim", "Surf", "Walk", "Relax", "Shell", "Picnic", "Sun", "Read", "Fish", "Work", "Eat"),main="What activities do you engage in while at the beach?")
Edited based on OP Comment:
data %>% gather(activity, ct, ActSwim:acteat) %>% filter(ct == 1) %>% count(activity) %>% ggplot(., aes(activity, n)) + geom_barplot(stat = "identity")
Basically converts the data into a tidy dataset which is tall rather than wide, filters just for 1 as the value and uses dplyr::count() to aggregate and feed into plot.
Edit: to facet by Gender:
data %>% gather(activity, ct, ActSwim:acteat) %>% filter(ct == 1) %>% count(activity, gender) %>% ggplot(., aes(activity, n)) + geom_barplot(stat = "identity") + facet_wrap(~gender, ncol = 2)