Classwork 11

Map Visualization I

Author

Byeong-Hak Choe

Published

April 15, 2026

Modified

April 15, 2026

Loading R packages

library(tidyverse)
library(rmarkdown)
library(skimr)
library(ggthemes)
library(socviz)
library(geofacet)

Part 1. Climate Opinion Map

The following data is for Part 1:

climate_opinion_long <- read_csv(
  'https://bcdanl.github.io/data/climate_opinion_2021.csv')



Variable Description

  • belief:
    • human: Estimated percentage who think that global warming is caused mostly by human activities.
    • happening: Estimated percentage who think that global warming is happening.

Question 1

  • Filter climate_opinion_long, so that climate_opinion_long has only estimated percentage of people who think that global warming is caused mostly by human activities.

Answer:



Question 2

  • Join the two data.frames, socviz::county_map and the resulting data.frame in Question 1.
county_map <- 
  read_csv("https://bcdanl.github.io/data/socviz_county_map.csv")


Answer:



Question 3

  • Replicate the above map.
    • Do not use coord_map(projection = "albers", lat0 = 39, lat1 = 45).
p_caption <- "Sources: Yale Program on Climate Change Communication\n(https://climatecommunication.yale.edu/visualizations-data/ycom-us/)"

Answer:



Part 2. Pitbull in NYC

The following data set is for Part 2:

nyc_dog_license <- read_csv(
  'https://bcdanl.github.io/data/nyc_dog_license.csv')
nyc_zips_coord <- read_csv(
  'https://bcdanl.github.io/data/nyc_zips_coord.csv')
nyc_zips_df <- read_csv(
  'https://bcdanl.github.io/data/nyc_zips_df.csv')


Question 4

  • Replicate the above ggplot.

    • You should calculate the proportion of Pit Bull (or Mix) for each zip code.
    • You should join data.frames properly.
    • Choose the color palette from the viridis scales
    • Use coord_map(projection = "albers", lat0 = 39, lat1 = 45).
    • To insert the image, use the following annotate():
# install.packages("ggtext")
library(ggtext)

annotate("richtext", 
          x =  , 
          y = quantile(DATAFRAME$Y, .60, na.rm = T), 
         label = "<img src='https://bcdanl.github.io/lec_figs/pitbull.png' width='750'/>", 
         fill = NA,
         color = NA) 


  • Note that the size of ggplot figure is 6.18 (width) x 6.84 (height)
```{.r}
#| fig-width: 6.18
#| fig-height: 6.84

# YOUR CODE IS HERE
```

Answer:


Question 5

  • Write an R code to identify the zip_code with the highest proportion of Pit Bull (or Mix), as shown above.

Answer:



Part 3. Unemployment Rate Maps with geofacet::facet_geo()

The following data is for Part 3:

unemp_house_prices <- read_csv(
  'https://bcdanl.github.io/data/unemp_house_prices.csv')


Question 6

Use geom_area(), geom_line(), and facet_geo(~state, labeller = adjust_labels) to replicate the above figure.

  • Since the date column in the unemp_house_prices data.frame is of type Date, you may need to use ymd() to convert a character string like "2008-01-01" into a Date value:
unemp_house_prices |> 
  filter(
    date >= ymd("2008-01-01")
  )
scale_x_date(
    breaks = ymd(c("2009-01-01", "2011-01-01", 
                   "2013-01-01", "2015-01-01", "2017-01-01"))
  )
  • Use the following as_labeller() for labeling lengthy state names:
adjust_labels <- as_labeller(
  function(x) {
    case_when(
      x == "New Hampshire" ~ "N. Hampshire",
      x == "District of Columbia" ~ "DC",
      x == "North Carolina" ~ "N. Carolina",
      x == "South Carolina" ~ "S. Carolina",
      TRUE ~ x
    )
  }
)


Answer:



Discussion

Welcome to our Classwork 11 Discussion Board! ๐Ÿ‘‹

This space is designed for you to engage with your classmates about the material covered in Classwork 11.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 11 materials or need clarification on any points, donโ€™t hesitate to ask here.

All comments will be stored here.

Letโ€™s collaborate and learn from each other!

Back to top