-
Notifications
You must be signed in to change notification settings - Fork 0
/
Map Notebook.Rmd
90 lines (75 loc) · 3.02 KB
/
Map Notebook.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
88
89
90
---
title: "Map Notebook"
output: html_notebook
---
**code source:** <https://jtr13.github.io/cc19/different-ways-of-plotting-u-s-map-in-r.html>
```{r}
library(tidyverse)
library(usmap)
library(mapdata)
```
```{r}
plot_usmap(regions = "states") +
labs(title = "U.S. States",
subtitle = "This is a blank map of the United States.") +
theme(panel.background=element_blank())
```
```{r}
plot_usmap(regions = "counties") +
labs(title = "U.S. counties",
subtitle = "This is a blank map of the United States.") +
theme(panel.background=element_blank())
```
```{r}
plot_usmap(include = .south_region, exclude = c("VA"), labels = TRUE)
```
```{r}
plot_usmap(include = c("CT", "ME", "MA", "NH", "VT")) +
labs(title = "New England Region") +
theme(panel.background = element_rect(color = "blue"))
```
```{r}
plot_usmap(data = countypov, values = "pct_pov_2014", include = c("CT", "ME", "MA", "NH", "VT"), color = "blue") +
scale_fill_continuous(low = "white", high = "blue", name = "Poverty Percentage Estimates", label = scales::comma) +
labs(title = "New England Region", subtitle = "Poverty Percentage Estimates for New England Counties in 2014") +
theme(legend.position = "right")
```
```{r}
plot_usmap(data = countypop, values = "pop_2015", include = .new_england, color = "red") +
scale_fill_continuous(low = "white", high = "red", name = "Population", label = scales::comma) +
labs(title = "New England Region", subtitle = "Population in New England Counties in 2014") +
theme(legend.position = "right")
```
```{r}
usa <- map_data('usa')
ggplot(data=usa, aes(x=long, y=lat, group=group)) +
geom_polygon(fill='lightblue') +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
ggtitle('U.S. Map') +
coord_fixed(1.3)
```
```{r}
state <- map_data("state")
ggplot(data=state, aes(x=long, y=lat, fill=region, group=group)) +
geom_polygon(color = "white") +
guides(fill=FALSE) +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
ggtitle('U.S. Map with States') +
coord_fixed(1.3)
```
```{r}
washington <- subset(state, region=="washington")
counties <- map_data("county")
washington_county <- subset(counties, region=="washington")
ca_map <- ggplot(data=washington, mapping=aes(x=long, y=lat, group=group)) +
coord_fixed(1.3) +
geom_polygon(color="black", fill="gray") +
geom_polygon(data=washington_county, fill=NA, color="white") +
geom_polygon(color="black", fill=NA) +
ggtitle('Washington Map with Counties') +
theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank())
ca_map
```