r - ggplot plot only the 1 on same graph remove 0 for a MQC -



r - ggplot plot only the 1 on same graph remove 0 for a MQC -

suppose have 1 question 8 choices. respondent can select minimum 1 selection , maximum 2 choices. have coded dummy each choice.

now it's easy utilize ggplot plot 8 graph each graph containing yes , no barplot. question how utilize ggplot in order create single plot removes no , maintain yes (so in case graph should have 8 yes bar)

respondant1 = c("yes","no","no","no","no","no","no","yes") respondant2 = c("yes","no","no","no","no","no","no","yes") respondant3 = c("no","no","no","no","yes","no","no","no") respondant4 = c("no","yes","no","no","no","yes","no","no") respondant5 = c("no","no","yes","no","no","no","no","no") respondant6 = c("no","yes","no","no","no","no","no","no") respondant7 = c("no","no","no","no","no","no","yes","yes") respondant8 = c("no","no","no","yes","no","no","no","no") new = rbind(respondant1,respondant2,respondant3,respondant4, respondant5,respondant6,respondant7,respondant8) new = as.data.frame(new)

conversion factor (the first line) not necessary, however, factor suitable info construction responses. thing left aggregate positive scores, , utilize geom_bar stat=identity.

new[] <- lapply(new, function(x) factor(x, levels = c('yes', 'no'))) yes_plot <- data.frame(question=colnames(new), yes=sapply(new, function(x) sum(x == 'yes'))) ggplot(yes_plot, aes(question, yes)) + geom_bar(stat='identity')

r merge ggplot2 dummy-data

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -