Visualizing Likert data II

Lecture 16

Dr. Mine Çetinkaya-Rundel

Duke University
STA 313 - Spring 2023

Warm up

Announcements

  • Teams emailed at the end of class
  • HW 4 will be posted before Monday

Setup

# load packages
library(countdown)
library(tidyverse)
library(colorspace)
library(waffle)

# set theme for ggplot2
ggplot2::theme_set(ggplot2::theme_minimal(base_size = 14))

# set width of code output
options(width = 65)

# set figure parameters for knitr
knitr::opts_chunk$set(
  fig.width = 7,        # 7" width
  fig.asp = 0.618,      # the golden ratio
  fig.retina = 3,       # dpi multiplier for displaying HTML output on retina
  fig.align = "center", # center align figures
  dpi = 300             # higher dpi, sharper image
)

Durham City and County Resident Survey

Data

durham <- read_csv(here::here("slides/16", "data/durham-2020.csv"))
glimpse(durham)
Rows: 848
Columns: 49
$ id                                      <dbl> 1, 2, 3, 4, 5, …
$ overall_quality_of_services_3_01        <dbl> 3, 4, 4, 4, 4, …
$ overall_quality_of_services_3_02        <dbl> 3, 4, 4, 4, 4, …
$ overall_appearance_of_durham_3_03       <dbl> 2, 4, 4, 4, 4, …
$ overall_management_of_develo_3_04       <dbl> 2, 2, 4, 4, 3, …
$ overall_image_of_durham_3_05            <dbl> 2, 4, 4, 4, 2, …
$ overall_quality_of_life_in_d_3_06       <dbl> 2, 4, 4, 3, 4, …
$ overall_quality_of_life_in_y_3_07       <dbl> 5, 5, 4, 4, 5, …
$ overall_value_you_receive_fo_3_08       <dbl> 3, 5, 4, 4, 3, …
$ do_your_monthly_housing_cost_12_01      <dbl> 2, 2, 2, NA, 2,…
$ are_you_able_to_find_housing_12_02      <dbl> 1, NA, 1, 1, 1,…
$ do_you_have_major_home_repai_12_03      <dbl> 2, 1, 2, 2, 2, …
$ ease_of_travel_by_walking_18_01         <dbl> NA, 4, 2, 4, 4,…
$ ease_of_travel_by_biking_18_02          <dbl> NA, 3, 2, 3, 4,…
$ ease_of_travel_by_bus_godu_18_03        <dbl> NA, 3, 2, 3, NA…
$ quality_of_downtown_parking_18_04       <dbl> 2, 3, 3, 3, 3, …
$ the_ability_in_your_neighbo_18_05       <dbl> 4, 5, 4, 4, 4, …
$ as_a_place_to_live_24_01                <dbl> 3, 5, 4, 4, 4, …
$ as_a_place_to_work_24_02                <dbl> 4, 4, NA, 4, NA…
$ as_a_place_to_play_24_03                <dbl> 3, 4, NA, 4, 3,…
$ as_a_place_to_raise_childre_24_04       <dbl> 2, 4, NA, NA, 2…
$ as_a_place_to_educate_child_24_05       <dbl> 2, 4, NA, NA, 1…
$ as_a_place_to_retire_24_06              <dbl> 2, 4, 4, 4, 4, …
$ as_a_place_to_visit_24_07               <dbl> 3, 4, 3, 3, 5, …
$ as_a_place_to_start_a_busin_24_08       <dbl> 3, 4, NA, 3, NA…
$ as_a_community_that_is_movi_24_09       <dbl> 1, 5, 4, 4, 3, …
$ have_you_or_someone_in_your_househol_26 <dbl> 2, 2, 2, 2, 2, …
$ approximately_how_many_years_have_yo_28 <dbl> 29, 34, 15, 11,…
$ what_is_your_age_29                     <dbl> 1, 3, 2, 1, 1, …
$ what_is_your_gender_30                  <dbl> 1, 2, 1, 2, 1, …
$ do_you_own_or_rent_your_current_resi_31 <dbl> 1, 2, 1, 1, 1, …
$ asianpacific_islander_32_01             <dbl> NA, NA, NA, NA,…
$ white_32_02                             <dbl> NA, 2, 2, 2, NA…
$ native_americaninuit_32_03              <dbl> NA, NA, NA, NA,…
$ blackafrican_american_32_04             <dbl> 4, NA, NA, NA, …
$ other_32_05                             <dbl> NA, NA, NA, NA,…
$ please_define_other_32_5                <chr> NA, NA, NA, NA,…
$ are_you_of_hispanic_latino_or_spa_33    <dbl> 2, 2, 1, 2, 2, …
$ primary_language                        <chr> "English", "Eng…
$ please_define_other_34_3                <chr> NA, NA, NA, NA,…
$ how_might_we_better_provide_service_34a <chr> NA, NA, NA, NA,…
$ would_you_say_your_total_annual_hous_35 <dbl> 1, 2, NA, NA, 3…
$ city                                    <chr> "Durham", "Durh…
$ state                                   <chr> "NC", "NC", "NC…
$ zip                                     <dbl> 27712, 27705, 2…
$ pac_zone                                <dbl> NA, 2, NA, 4, 4…
$ inside_city_of_durham                   <chr> "N", "Y", "N", …
$ block_lon                               <dbl> -78877000, -789…
$ block_lat                               <dbl> 36087000, 36022…

Quality

Quality

durham |>
  select(contains("_3_")) |>
  glimpse()
Rows: 848
Columns: 8
$ overall_quality_of_services_3_01  <dbl> 3, 4, 4, 4, 4, 3, 5, …
$ overall_quality_of_services_3_02  <dbl> 3, 4, 4, 4, 4, 4, 4, …
$ overall_appearance_of_durham_3_03 <dbl> 2, 4, 4, 4, 4, 4, 4, …
$ overall_management_of_develo_3_04 <dbl> 2, 2, 4, 4, 3, 2, 3, …
$ overall_image_of_durham_3_05      <dbl> 2, 4, 4, 4, 2, 1, 4, …
$ overall_quality_of_life_in_d_3_06 <dbl> 2, 4, 4, 3, 4, 4, 4, …
$ overall_quality_of_life_in_y_3_07 <dbl> 5, 5, 4, 4, 5, 4, 3, …
$ overall_value_you_receive_fo_3_08 <dbl> 3, 5, 4, 4, 3, 3, 4, …

Transportation

Transportation

durham |>
  select(contains("_18_")) |>
  glimpse()
Rows: 848
Columns: 5
$ ease_of_travel_by_walking_18_01   <dbl> NA, 4, 2, 4, 4, 3, 2,…
$ ease_of_travel_by_biking_18_02    <dbl> NA, 3, 2, 3, 4, 2, 3,…
$ ease_of_travel_by_bus_godu_18_03  <dbl> NA, 3, 2, 3, NA, 3, N…
$ quality_of_downtown_parking_18_04 <dbl> 2, 3, 3, 3, 3, 3, 4, …
$ the_ability_in_your_neighbo_18_05 <dbl> 4, 5, 4, 4, 4, 4, 2, …

Ratings

Ratings

durham |>
  select(contains("_24_")) |>
  glimpse()
Rows: 848
Columns: 9
$ as_a_place_to_live_24_01          <dbl> 3, 5, 4, 4, 4, 4, 4, …
$ as_a_place_to_work_24_02          <dbl> 4, 4, NA, 4, NA, 5, N…
$ as_a_place_to_play_24_03          <dbl> 3, 4, NA, 4, 3, 3, NA…
$ as_a_place_to_raise_childre_24_04 <dbl> 2, 4, NA, NA, 2, 4, N…
$ as_a_place_to_educate_child_24_05 <dbl> 2, 4, NA, NA, 1, 4, N…
$ as_a_place_to_retire_24_06        <dbl> 2, 4, 4, 4, 4, 4, NA,…
$ as_a_place_to_visit_24_07         <dbl> 3, 4, 3, 3, 5, 4, 4, …
$ as_a_place_to_start_a_busin_24_08 <dbl> 3, 4, NA, 3, NA, NA, …
$ as_a_community_that_is_movi_24_09 <dbl> 1, 5, 4, 4, 3, 3, 4, …

Housing

Housing

durham |>
  select(contains("_12_")) |>
  glimpse()
Rows: 848
Columns: 3
$ do_your_monthly_housing_cost_12_01 <dbl> 2, 2, 2, NA, 2, 2, 2…
$ are_you_able_to_find_housing_12_02 <dbl> 1, NA, 1, 1, 1, 1, 1…
$ do_you_have_major_home_repai_12_03 <dbl> 2, 1, 2, 2, 2, 2, 2,…

Demographics

Demographics

durham |>
  select(
    !contains("_3_") & !contains("_12_") & 
    !contains("_18_") & !contains("_24_")) |>
  glimpse()
Rows: 848
Columns: 24
$ id                                      <dbl> 1, 2, 3, 4, 5, …
$ have_you_or_someone_in_your_househol_26 <dbl> 2, 2, 2, 2, 2, …
$ approximately_how_many_years_have_yo_28 <dbl> 29, 34, 15, 11,…
$ what_is_your_age_29                     <dbl> 1, 3, 2, 1, 1, …
$ what_is_your_gender_30                  <dbl> 1, 2, 1, 2, 1, …
$ do_you_own_or_rent_your_current_resi_31 <dbl> 1, 2, 1, 1, 1, …
$ asianpacific_islander_32_01             <dbl> NA, NA, NA, NA,…
$ white_32_02                             <dbl> NA, 2, 2, 2, NA…
$ native_americaninuit_32_03              <dbl> NA, NA, NA, NA,…
$ blackafrican_american_32_04             <dbl> 4, NA, NA, NA, …
$ other_32_05                             <dbl> NA, NA, NA, NA,…
$ please_define_other_32_5                <chr> NA, NA, NA, NA,…
$ are_you_of_hispanic_latino_or_spa_33    <dbl> 2, 2, 1, 2, 2, …
$ primary_language                        <chr> "English", "Eng…
$ please_define_other_34_3                <chr> NA, NA, NA, NA,…
$ how_might_we_better_provide_service_34a <chr> NA, NA, NA, NA,…
$ would_you_say_your_total_annual_hous_35 <dbl> 1, 2, NA, NA, 3…
$ city                                    <chr> "Durham", "Durh…
$ state                                   <chr> "NC", "NC", "NC…
$ zip                                     <dbl> 27712, 27705, 2…
$ pac_zone                                <dbl> NA, 2, NA, 4, 4…
$ inside_city_of_durham                   <chr> "N", "Y", "N", …
$ block_lon                               <dbl> -78877000, -789…
$ block_lat                               <dbl> 36087000, 36022…

Visualizing categorical data

Language

What is the primary language used in your household?

durham |> distinct(primary_language)
# A tibble: 4 × 1
  primary_language
  <chr>           
1 English         
2 Spanish         
3 <NA>            
4 Other           
durham <- durham |>
  mutate(
    primary_language = fct_relevel(primary_language, "English", "Spanish", "Other")
  )

Bar chart

durham |>
  filter(!is.na(primary_language)) |>
  ggplot(aes(x = primary_language)) +
  geom_bar()

Pie chart

Waffle chart

Using waffle

Proportional waffle chart

Waffles work best when they are square – makes it easier to compare parts to whole which is the purpose of the chart

But what happened to “Other”?

Proportional waffle chart, take 2

With a bit of fudging…

Let’s actually make these figures!

Go to ae-14.

Visualizing Likert data

Quality

durham |>
  select(contains("_3_")) |>
  glimpse()
Rows: 848
Columns: 8
$ overall_quality_of_services_3_01  <dbl> 3, 4, 4, 4, 4, 3, 5, …
$ overall_quality_of_services_3_02  <dbl> 3, 4, 4, 4, 4, 4, 4, …
$ overall_appearance_of_durham_3_03 <dbl> 2, 4, 4, 4, 4, 4, 4, …
$ overall_management_of_develo_3_04 <dbl> 2, 2, 4, 4, 3, 2, 3, …
$ overall_image_of_durham_3_05      <dbl> 2, 4, 4, 4, 2, 1, 4, …
$ overall_quality_of_life_in_d_3_06 <dbl> 2, 4, 4, 3, 4, 4, 4, …
$ overall_quality_of_life_in_y_3_07 <dbl> 5, 5, 4, 4, 5, 4, 3, …
$ overall_value_you_receive_fo_3_08 <dbl> 3, 5, 4, 4, 3, 3, 4, …

Services visualized

A very rough starting point:

Let’s improve!

Go back to ae-14.