Reputation: 1
I am trying to make some barplots with my data but I keep hitting some walls. If someone on here could help that'd be great
I wanted to create barplots with side by side comparison of pre vs post responses, I need the x axis to be the response type (agree/disagree, etc.) and the y to be percentage of responses
This feels super basic but its a toughie. Any help with R code to use would be amazing. I'm also providing the dataframe I used.
data<- structure(list(Sample = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43"), ID = c("Resident", "Resident", "City_personal",
"Manager_staff", "Resident", "Manager_staff", "Manager_staff",
"Manager_staff", "Resident", "Manager_staff", "Manager_staff",
"Manager_staff", "Manager_staff", "Manager_staff", "Manager_staff",
"Manager_staff", "Manager_staff", "City_personal", "Resident",
"Manager_staff", "Resident", "Manager_staff", "Resident", "Resident",
"City_personal", "Manager_staff", "Resident", "Resident", "Resident",
"Manager_staff", "City_personal", "City_personal", "City_personal",
"City_personal", "City_personal", "City_personal", "City_personal",
"City_personal", "City_personal", "City_personal", "City_personal",
"City_personal", "City_personal"), envir_conscious = c("Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Strongly_agree", "Strongly_disagree", "Neutral", "Agree", "Agree",
"Agree", "Agree", "Strongly_disagree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Agree",
"Strongly_agree", "Strongly_agree", "Agree", "Strongly_disagree",
"Agree", "Agree", "Strongly_agree", "Strongly_disagree", "Agree",
"Strongly_agree", "Strongly_agree", "Agree", "Agree", "Agree",
"Neutral", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Agree", "Agree", "Agree", "Strongly_agree", "Agree"), PRE_understand = c("Agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Strongly_disagree", "Neutral", "Agree", "Neutral", "Agree",
"Disagree", "Strongly_disagree", "Agree", "Strongly_agree", "Agree",
"Strongly_agree", "Strongly_agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Neutral", "Neutral", "Agree",
"Neutral", "Neutral", "Strongly_agree", "Agree", "Agree", "Agree",
"Agree", "Neutral", "Agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Agree", "Agree", "Neutral"
), PRE_serious_prob = c("Strongly_agree", "Strongly_agree", "Agree",
"Agree", "Agree", "Agree", "Strongly_agree", "Strongly_disagree",
"Neutral", "Neutral", "Strongly_agree", "Agree", "Neutral", "Strongly_disagree",
"Agree", "Strongly_agree", "Unsure", "Strongly_agree", "Strongly_agree",
"Agree", "Strongly_agree", "Strongly_agree", "Agree", "Neutral",
"Strongly_agree", "Neutral", "Agree", "Neutral", "Neutral", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Agree",
"Agree", "Agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Agree", "Neutral"), PRE_confident = c("Agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Disagree", "Neutral", "Agree", "Strongly_agree", "Agree", "Neutral",
"Strongly_disagree", "Agree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Disagree", "Strongly_agree", "Strongly_agree",
"Agree", "Neutral", "Neutral", "Unsure", "Agree", "Neutral",
"Neutral", "Strongly_agree", "Strongly_agree", "Neutral", "Neutral",
"Neutral", "Agree", "Agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Agree", "Agree", "Neutral"
), PRE_willing = c("Strongly_agree", "Strongly_agree", "Agree",
"Neutral", "Agree", "Agree", "Strongly_agree", "Strongly_disagree",
"Neutral", "Agree", "Strongly_agree", "Agree", "Agree", "Strongly_disagree",
"Agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Agree", "Strongly_agree", "Strongly_agree",
"Agree", "Strongly_disagree", "Agree", "Unsure", "Agree", "Strongly_disagree",
"Agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Agree", "Agree", "Agree", "Agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree"), PRE_attain = c("Neutral",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Disagree", "Neutral", "Agree", "Strongly_agree", "Agree", "Neutral",
"Strongly_disagree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Strongly_agree", "Agree",
"Agree", "Neutral", "Unsure", "Strongly_agree", "Agree", "Strongly_agree",
"Agree", "Agree", "Agree", "Strongly_agree", "Agree", "Disagree",
"Unsure", "Strongly_agree", "Agree", "Agree", "Agree"), res_time = c("less_than_5_yrs",
"less_than_5_yrs", "less_than_5_yrs", "10_yrs", "less_than_5_yrs",
"5_to_10_yrs", "less_than_5_yrs", "10_yrs", "10_yrs", "less_than_5_yrs",
"less_than_5_yrs", "less_than_5_yrs", "less_than_5_yrs", "10_yrs",
"less_than_5_yrs", "less_than_5_yrs", "less_than_5_yrs", "less_than_5_yrs",
"5_to_10_yrs", "less_than_5_yrs", "10_yrs", "5_to_10_yrs", "10_yrs",
"10_yrs", "less_than_5_yrs", "10_yrs", "10_yrs", "10_yrs", "10_yrs",
"less_than_5_yrs", "10_yrs", "less_than_5_yrs", "less_than_5_yrs",
"less_than_5_yrs", "less_than_5_yrs", "5_to_10_yrs", "less_than_5_yrs",
"less_than_5_yrs", "5_to_10_yrs", "less_than_5_yrs", "less_than_5_yrs",
"10_yrs", "less_than_5_yrs"), nature_feeling = c("Yes", "Yes",
"Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes_IDK", "Yes", "Yes",
"Yes_IDK", "Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "Yes",
"Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "No",
"Yes", "Yes_IDK", "Yes", "Yes", "Yes", "No", "Yes", "No", "Yes",
"Yes", "Yes", "Yes", "Yes_IDK", "Yes"), seen_turtle = c("Yes",
"No", "Yes", "Yes", "Yes", "Yes", "Yes", "No", "No", "Yes", "Yes",
"Yes", "Yes", "No", "Yes", "No", "Yes", "Yes", "Yes", "Yes",
"Yes", "Yes", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "Yes",
"Yes", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes",
"No", "Yes", "Yes", "Yes"), active_envir = c("Yes_less_than_3",
"First", "First", "Yes_less_than_3", "Yes_over_1", "Yes_over_1",
"Yes_less_than_3", "First", "Unsure", "First", "Yes_over_1",
"First", "Unsure", "First", "First", "Yes_more_than_3", "Yes_over_1",
"Yes_over_1", "Yes_more_than_3", "Unsure", "Yes_more_than_3",
"First", "Yes_more_than_3", "First", "Yes_less_than_3", "Yes_less_than_3",
"Yes_over_1", "First", "Yes_over_1", "Yes_over_1", "Yes_over_1",
"Yes_over_1", "Yes_over_1", "First", "First", "Yes_over_1", "First",
"Yes_over_1", "Yes_over_1", "Yes_over_1", "First", "Yes_over_1",
"Yes_more_than_3"), Too_Expensive = c("Unsure", "Strongly_disagree",
"Agree", "Neutral", "Neutral", "Unsure", "Strongly_disagree",
"Disagree", "Disagree", "Disagree", "Disagree", "Disagree", "Neutral",
"Disagree", "Disagree", "Disagree", "Disagree", "Unsure", "Agree",
"Neutral", "Disagree", "Strongly_disagree", "Disagree", "Strongly_disagree",
"Strongly_disagree", "Neutral", "Disagree", "Strongly_disagree",
"Strongly_disagree", "Disagree", "Neutral", "Neutral", "Neutral",
"Disagree", "Neutral", "Neutral", "Neutral", "Strongly_disagree",
"Disagree", "Strongly_disagree", "Strongly_disagree", "Neutral",
"Neutral"), Not_aesthetic = c("Strongly_disagree", "Strongly_disagree",
"Agree", "Disagree", "Neutral", "Unsure", "Strongly_disagree",
"Disagree", "Strongly_disagree", "Disagree", "Strongly_disagree",
"Disagree", "Strongly_disagree", "Disagree", "Strongly_disagree",
"Disagree", "Disagree", "Neutral", "Disagree", "Neutral", "Disagree",
"Strongly_disagree", "Disagree", "Strongly_disagree", "Strongly_disagree",
"Unsure", "Strongly_disagree", "Strongly_disagree", "Strongly_disagree",
"Disagree", "Unsure", "Strongly_disagree", "Disagree", "Disagree",
"Neutral", "Unsure", "Neutral", "Strongly_disagree", "Disagree",
"Disagree", "Strongly_disagree", "Neutral", "Neutral"), Safety_concern = c("Strongly_disagree",
"Strongly_disagree", "Agree", "Disagree", "Disagree", "Unsure",
"Strongly_disagree", "Strongly_disagree", "Strongly_disagree",
"Disagree", "Strongly_disagree", "Strongly_agree", "Disagree",
"Disagree", "Neutral", "Agree", "Disagree", "Agree", "Disagree",
"Neutral", "Disagree", "Disagree", "Strongly_disagree", "Strongly_disagree",
"Disagree", "Agree", "Strongly_disagree", "Strongly_disagree",
"Neutral", "Disagree", "Strongly_agree", "Strongly_disagree",
"Neutral", "Agree", "Neutral", "Strongly_agree", "Neutral", "Strongly_disagree",
"Agree", "Strongly_disagree", "Strongly_disagree", "Strongly_disagree",
"Neutral"), POST_understand = c("Strongly_agree", "Strongly_agree",
"Agree", "Agree", "Agree", "Agree", "Strongly_agree", "Strongly_disagree",
"Strongly_agree", "Agree", "Strongly_agree", "Strongly_agree",
"Unsure", "Strongly_disagree", "Neutral", "Strongly_agree", "Disagree",
"Strongly_agree", "Strongly_agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Neutral",
"Strongly_agree", "Neutral", "Agree", "Neutral", "Strongly_agree",
"Neutral", "Strongly_agree", "Agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Neutral"), POST_serious_prob = c("Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Strongly_disagree", "Unsure", "Agree", "Strongly_agree", "Strongly_agree",
"Unsure", "Strongly_disagree", "Neutral", "Strongly_agree", "Disagree",
"Strongly_agree", "Strongly_agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Strongly_agree", "Neutral",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Neutral", "Strongly_agree", "Agree", "Strongly_agree", "Neutral",
"Agree", "Neutral", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Neutral"), POST_confident = c("Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Agree", "Strongly_agree",
"Strongly_disagree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Unsure", "Strongly_disagree", "Neutral", "Strongly_agree",
"Disagree", "Strongly_agree", "Strongly_agree", "Disagree", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Strongly_agree", "Agree",
"Agree", "Neutral", "Neutral", "Agree", "Neutral", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Neutral"), POST_willing = c("Strongly_agree", "Strongly_agree",
"Agree", "Agree", "Neutral", "Agree", "Agree", "Strongly_disagree",
"Strongly_agree", "Agree", "Strongly_agree", "Strongly_agree",
"Unsure", "Strongly_disagree", "Disagree", "Strongly_agree",
"Disagree", "Strongly_agree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Agree", "Strongly_disagree", "Agree", "Neutral",
"Strongly_agree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Agree", "Agree", "Agree", "Neutral", "Agree",
"Neutral", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Neutral"), POST_attain = c("Agree",
"Strongly_agree", "Agree", "Agree", "Neutral", "Unsure", "Strongly_agree",
"Strongly_disagree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Agree", "Strongly_disagree", "Unsure", "Strongly_agree",
"Disagree", "Strongly_agree", "Strongly_agree", "Agree", "Strongly_agree",
"Strongly_agree", "Agree", "Neutral", "Strongly_agree", "Unsure",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Strongly_agree",
"Strongly_agree", "Strongly_agree", "Strongly_agree", "Unsure",
"Neutral", "Agree", "Neutral", "Strongly_agree", "Neutral", "Strongly_agree",
"Agree", "Agree", "Neutral")), row.names = 2:44, class = "data.frame")
I tried barplot, ggplot, but nothing. I've made them into as.factors but still cant get a figure with error bars.
Upvotes: -1
Views: 43
Reputation: 24149
Given the data above here is the basic code to plot the first column:
library(ggplot2)
#responses
levels <- c("Strongly_disagree", "Disagree" , "Neutral", "Agree", "Strongly_agree")
#convert to factors in the proper order
data$envir_conscious <- factor(data$envir_conscious, levels=levels)
#plot
ggplot(data, aes(x=envir_conscious)) +
geom_bar()
Upvotes: 0