Chart Your Own Survey SOCL 3633 Research Methods · Lab 9 · Midwestern State University

Two weeks ago you launched a survey. Today you find out what your respondents said. You load your responses into R, chart a shared question and one of your own, and count how many people fall into each group. Keep this page open next to RStudio and work through the tabs in order. Before you leave, you submit two things in the Lab 9 submission on D2L: your response sheet and the picture file of your own chart.

Get set up

Checkpoint. nrow(survey) prints the number of people who answered your survey. The practice file has 16.

Two new tools today

read_csv()
Reads a CSV file, the kind Google Forms downloads, into R. Each row is one respondent, and each column is one question.
factor(..., levels = )
Tells R the order of the answer choices. Without it, R sorts text answers alphabetically, so "Somewhat dissatisfied" would come before "Very dissatisfied."

If something goes wrong

What you seeWhat to do
"my_survey.csv does not exist in current working directory"The file is in a different folder, or its name is different. Check the Files pane. Then click Session, Set Working Directory, To Source File Location, and run Step 1 again.
The file is named my_survey.csv.csv, or it is a .zip fileWindows hides file endings, so typing ".csv" can add a second one. Rename it so the full name is my_survey.csv. If you have a .zip file, open it and take out the .csv file.
A + sign in the ConsoleA parenthesis or quotation mark is missing. Press Escape in the Console, fix the line, and run it again.

A shared question: Steps 2 to 4

Step 2: rename the shared questions

Run the three names() lines and glimpse(survey). These lines work for everyone because questions 1 to 3 are in the same place in every form.

Step 3: count before you chart

Put satisfaction in the blank and run the line.

Checkpoint. With the practice file: Somewhat dissatisfied 3, Somewhat satisfied 9, Very satisfied 4. Nobody chose Very dissatisfied, so it is not in the count. A row that says NA counts people who skipped the question.

Step 4: put the answers in order, then chart them

  1. Run the mutate(satisfaction = factor(...)) lines. They set the order from least to most satisfied.
  2. Put satisfaction in the blank in the chart lines. Replace the subtitle with a description of your respondents, such as "15 friends and coworkers, mostly ages 18 to 25." Run all the chart lines, then print(satisfaction_chart).
Bar chart of life satisfaction among 16 respondents in the practice file: very dissatisfied, 0; somewhat dissatisfied, 3; somewhat satisfied, 9; very satisfied, 4.
This is the chart from the practice file. Yours will look different. "Very dissatisfied" stays on the chart with no bar because of scale_y_discrete(drop = FALSE): a choice nobody picked is still a result.

On your own: Step 5, your question 4

Column 5 holds your question 4, the first question you wrote. You chart it the same way you charted satisfaction, but you set the order of the answer choices yourself.

  1. Run the names(survey)[5] line, then count(survey, my_question). Look at the exact spelling of each answer choice.
  2. In the levels = c(____) blank, type each answer choice inside quotation marks, separated by commas, in the order you want from the bottom of the chart to the top. Copy the spelling from the count. Run the lines.
  3. Run the chart lines. Look at the chart, then replace "Write your title here" with a complete sentence of about ten words that says what it shows, and write your own subtitle. Run the chart lines again.
  4. Write one ggsave() line that saves my_chart with your last name, for example smith_lab9.png, and run it.
If a bar labeled NA appears after you set the levels, one choice in your levels list is spelled differently from the data, so R could not match it. Compare the spelling with your count, fix it, and run Step 5 again from the mutate() line. If the NA bar was also in your count before you set the levels, it shows people who skipped the question. Keep it, and mention it in your answers.
There is no example chart for this step, because everyone's question 4 is different. A strong title states the result, for example "Most of my 15 respondents check the news every day," not the topic alone.

How many in each group? Step 6

Your survey asked everyone question 3: student, working full-time, working part-time, or other. Step 6 counts your question 4 answers within each of those groups.

  1. Put status in the blank and run the line.
  2. Each row is one combination of a status and an answer, and n is the number of people in it. Find the row with the smallest n.
Checkpoint. With the practice file, the table has 9 rows. Five of them hold just one person. The "Working part-time" group has only 2 people in all.
Recall the Lab 5 histograms: small samples jump around. When a group holds one or two people, a single respondent decides what the whole group looks like. That is why you report "2 of my 4 working respondents" rather than "50 percent of workers."
Before you leave: save the script in your SOCL3633 folder (File, then Save).

Lab 9 response sheet

Answer in complete sentences. Then assemble your answers and paste them into the Lab 9 submission in D2L. In the same submission, upload the picture file of your own chart. Your answers stay on this page and are not sent anywhere until you paste them.

Your name
Which data did you use?
1. How many people answered your survey, how many reminders did you send, and what subtitle did you use to describe your respondents?
One to three sentences. If you used the practice file, say why, and describe the practice respondents as the subtitle does.
2. Why should you report "6 of my 15 respondents" rather than "40 percent"?
Two to three sentences.
3. Look at your chart of question 4. Based on your Lab 8 table, did the question work as you planned? Name one change you would make to its wording or answer choices.
Three to four sentences.
4. In your table of question 4 by question 3, how many people are in the smallest group? What can and can't you say about that group?
Two to three sentences.
5. Who is missing from your sample, and how could the missing people change your charts?
Two to three sentences.

Sources

Wickham, Hadley. 2016. ggplot2: Elegant Graphics for Data Analysis. New York: Springer.
Wickham, Hadley, Jim Hester, and Jennifer Bryan. 2024. readr: Read Rectangular Text Data. R package. https://readr.tidyverse.org
Wickham, Hadley, Romain François, Lionel Henry, Kirill Müller, and Davis Vaughan. 2023. dplyr: A Grammar of Data Manipulation. R package. https://dplyr.tidyverse.org

The practice file example_survey_responses.csv contains invented responses written for this course. It does not describe real people.