-
Notifications
You must be signed in to change notification settings - Fork 0
/
vizome_map_edu.Rmd
88 lines (73 loc) · 2.37 KB
/
vizome_map_edu.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
---
title: "Map figure for ITCR educational resource grant"
author: "Pierrette Lo"
date: "12/16/2019"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(fiftystater)
library(viridis)
```
*** Same networks as U24 but different partners that Shannon sent me ***
Read in data
```{r}
data <- readxl::read_xlsx("centers_edu.xlsx")
point_data <- readxl::read_xlsx("partner_coords_edu.xlsx")
```
Clean up center data
```{r}
# make lookup table to convert state abbs to names from {state} dataset
# add dc from {fifty_states} (not contained in {state})
state_lookup <- data.frame(state.abb, state = tolower(state.name), stringsAsFactors = F) %>%
rbind(c("DC", "district of columbia"))
# add full state names to centers
centers <- data %>%
left_join(state_lookup, by = c("state_abb" = "state.abb"))
# lowercase center names for consistency
centers$center <- tolower(centers$center)
```
Version 2: keep states with 0 centers separate so they can be grey
```{r}
mapdata2 <- centers %>%
distinct(center, .keep_all = T) %>%
group_by(state) %>%
summarize(center_count = n()) %>%
ungroup()
zero_states <- state_lookup %>%
anti_join(mapdata2, by = "state")
```
Add state counts to point data
```{r}
point_data <- point_data %>%
add_count(state_abb)
```
Version 2 map: zero_states are grey (easier to see)
```{r}
ggplot() +
geom_map(data = mapdata2,
aes(map_id = state, fill = center_count),
map = fifty_states, color = "white") +
geom_map(data = zero_states,
aes(map_id = state),
map = fifty_states,
fill = "lightgrey",
color = "white") +
geom_point(data = point_data,
aes(x = long, y = lat, size = n),
shape = 21, fill = "darkorange") +
expand_limits(x = fifty_states$long, y = fifty_states$lat) +
coord_map() +
scale_fill_viridis(breaks = c(1, 7, 13),
name = "Network centers\nper state\n(grey = 0)") +
scale_x_continuous(breaks = NULL) +
scale_y_continuous(breaks = NULL) +
scale_size_continuous(breaks = c(1, 2),
range = c(3,5),
name = "Collaborators\nper state") +
labs(x = NULL, y = NULL) +
theme(panel.background = element_blank(),
plot.caption = element_text(hjust = 0.5, size = 10))
ggsave("map_edu.png", height = 5, width = 9)
```