rtidyversesurveymicrosoft-forms

Splitting answers and counting (and visualizing) the responses


I have responses coming from Microsoft Forms where people had a multiple choice option. It is part of a larger data frame and one ofc the columns with the responses coming from my CSV looks like the following:

Which method of transport do you use?
own car; bicycle
own car
own car; bicycle; public transport
public transport; something other that people where able to put in themselves
...

Now I would like to visualize this and count the responses. The ranking is not relevant (there was no option to click bicycle 1st place and so on).

I started with a simple

question1 <- df %>% strsplit(`Which method of transport do you use?`, ";")

That gave me a list, but I am not sure it is the right start and not sure how to move on from here to make some nice graphs and show the answers.

Thanks!


Solution

  • library(tidyr)
    library(ggplot2)
    
    data %>%  
      separate_rows(transport, sep = "; ") %>%  
      ggplot() + 
      aes(x = transport) + 
      geom_bar()
    

    Data:

    structure(list(transport = c("own car; bicycle", "own car", "own car; bicycle; public transport", 
    "public transport; something other")), row.names = c(NA, -4L), class = c("tbl_df", 
    "tbl", "data.frame"))
    

    enter image description here