Homework

Part 1. Color selection with paletteer

Before making your figures, choose one palette you think works well for categorical data and one that works well for ordered or numeric data.

Task 1

Use paletteer to explore palettes and answer the following:

  • What palette did you choose for categorical data?

we use qualitative palettes for categrical data, sequential palettes for sequential data, and diverging palettes when data is split about a midline.

#install.packages("paletteer")
library(paletteer)
library(dplyr)
library(scales)

#View(palettes_c_names)
# categorical palette
paletteer_d("RColorBrewer::Set2", n = 6) %>% show_col()

  • What palette did you choose for numeric data?
library(paletteer)
library(dplyr)
library(scales)

# numeric palette
paletteer_c("viridis::plasma", n = 6) %>% show_col()

  • In 3 to 5 sentences, explain why those choices make sense.

The RColorBrewer::Set2 palette works well for categorical data because each color is visually different enough to not confuse the viewer, making it easy to differentiate between groups. The viridis::plasma palette is good for numeric data because it provides a smooth gradient of colors that blend together well.

Requirements

  • Include the code you used to preview or extract palettes
  • Include 1 to 2 sentences on why color choice matters in scientific graphics

Color choice is important in graphics because it directly effects how easily viewers can interpret visual data.

Part 2. Bubble Maps

Create a bubble map in ggplot.

Requirements

  1. plot at least 5 locations
  2. use bubble size to represent a numeric value
  3. use color intentionally with a palette you selected
  4. include text labels for the locations
  5. include a title
  6. include a short caption or note explaining what size and color represent

Acceptable options

  • one map that includes both bubble size and labels
  • or two versions of the same map, one emphasizing color and one emphasizing labels

Suggested skills

  • geom_point()
  • geom_text() or geom_label()
  • coord_cartesian() if you want to zoom in
  • theme_void() or another clean theme
library(ggplot2)
library(dplyr)

# bubble plot
map_data <- tibble(
  location = c("one", "two", "three", "four", "five"),
  lat = c(40.71, 29.76, 34.05, 41.87, 25.76),
  long = c(-74.00, -95.36, -118.24, -87.62, -80.19),
  value = c(8.8, 2.3, 3.9, 2.7, 0.5)
)
head(map_data)
## # A tibble: 5 × 4
##   location   lat   long value
##   <chr>    <dbl>  <dbl> <dbl>
## 1 one       40.7  -74     8.8
## 2 two       29.8  -95.4   2.3
## 3 three     34.0 -118.    3.9
## 4 four      41.9  -87.6   2.7
## 5 five      25.8  -80.2   0.5
map_data %>%
  ggplot(aes(long, lat)) + 
  geom_point(aes(size = value, colour = value)) + 
  geom_text(vjust = +1.4, aes(label = location)) + 
  scale_color_paletteer_c(`"viridis::plasma"`) + 
  theme_minimal() + 
  labs(
    title = "Bubble Map Test", 
    x = "Longitude",
    y = "Latitude", 
    size = "Population Size", 
    colour = "Population Size"
  )

Part 3. Map variation with icon labels.

Make one variation of your map using icon labels.

Requirements

  1. include at least 3 labeled locations
  2. labels can be marker icons, point symbols, or custom styled labels
  3. keep it readable and not overcrowded
  4. write 2 to 4 sentences explaining how this labeling style changes the way the map feels or reads

Examples of what counts

  • a leaflet map with popup markers
  • a static map with special point shapes and labels
  • a map using marker icons or custom annotation
#install.packages("leaflet")
library(leaflet)
library(ggplot2)
library(dplyr)

# bubble plot
map_data <- tibble(
  location = c("one", "two", "three", "four", "five"),
  lat = c(40.71, 29.76, 34.05, 41.87, 25.76),
  long = c(-74.00, -95.36, -118.24, -87.62, -80.19),
  value = c(8.8, 2.3, 3.9, 2.7, 0.5)
)
head(map_data)
## # A tibble: 5 × 4
##   location   lat   long value
##   <chr>    <dbl>  <dbl> <dbl>
## 1 one       40.7  -74     8.8
## 2 two       29.8  -95.4   2.3
## 3 three     34.0 -118.    3.9
## 4 four      41.9  -87.6   2.7
## 5 five      25.8  -80.2   0.5
leaflet(data = map_data) %>%
   addTiles() %>%
   addCircleMarkers( ~long, ~lat)

using leaflet adds to the visualzation by making the map positions stand out more because there is an interactive background the viewer can see instead of a geom_minimal theme.

Part 4. Basic Sankey Diagram

You may invent a small dataset if needed. Keep it simple.

Example ideas

  1. students moving from major to career path
  2. genes grouped into pathway categories
  3. citation flow from field to topic
  4. patients moving from diagnosis group to treatment group

Build one Sankey diagram.

Requirements

  • include at least 3 source categories
  • include at least 3 destination categories
  • show flow values
  • use color intentionally
  • include a short figure caption explaining what the flows mean

Keep it basic: It does not need to be interactive or highly customized. The goal is to understand the structure.

# install.packages("networkD3")
library(networkD3)
library(dplyr)

# students moving from major to career path 
nodes <- data.frame(name = c("Biology", "Math", "Art", "Research", "Tech", "Design"))
links <- data.frame(
  source = c(0, 0, 1, 1, 2, 2), 
  target = c(3, 4, 4, 3, 5, 4),
  value = c(15, 5, 20, 10, 25, 5)
)

sankeyNetwork(Links = links, 
              Nodes = nodes, 
              Source = "source",
              Target = "target", 
              Value = "value", 
              NodeID = "name")

Part 5. Hierarchial edge building graph

Create one hierarchical edge bundling graph. You may use an example dataset from a package, adapt class example code, or create a very small hierarchy yourself.

Build one edge bundling graph.

Requirements

  1. include a hierarchical structure
  2. include linked nodes
  3. use color intentionally
  4. include a short paragraph answering:
  • What does the hierarchy represent?
  • What do the edges represent?
  • Why might edge bundling be useful compared with drawing all lines directly?

Note:This is meant to be an introduction, not a perfect polished figure. It is okay to rely on a tutorial example and then make small changes.

library(ggraph)
library(igraph)
library(tidyverse)