-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from pdil/feature/improve-plot-usmap-data-vign…
…ette Add data format information to mapping vignette
- Loading branch information
Showing
10 changed files
with
1,123 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## ----setup, include = FALSE--------------------------------------------------- | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
|
||
## ---- fig.align='center', fig.width=7, fig.height=5, message=FALSE, warning=FALSE---- | ||
usmap::plot_usmap("states", labels = TRUE) | ||
|
||
## ---- fig.align='center', fig.width=7, fig.height=5, message=FALSE, warning=FALSE---- | ||
usmap::plot_usmap("counties", include = c("MA", "CT", "RI"), labels = TRUE) | ||
|
||
## ---- fig.align='center', fig.width=7, fig.height=5, message=FALSE, warning=FALSE---- | ||
usmap::plot_usmap("counties", | ||
include = c("MA", "CT", "RI"), | ||
labels = TRUE, label_color = "blue") | ||
|
||
## ---- fig.align='center', fig.width=7, fig.height=5, message=FALSE, warning=FALSE---- | ||
usmap::plot_usmap("counties", | ||
include = c("MA", "CT", "RI"), | ||
labels = TRUE, label_color = "blue", | ||
fill = "yellow", alpha = 0.25, color = "orange", size = 2) | ||
|
||
## ----------------------------------------------------------------------------- | ||
usmap::usmap_crs()@projargs | ||
|
||
## ---- fig.align='center', fig.width=8, fig.height=5, message=FALSE, warning=FALSE---- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
eq_transformed <- usmap_transform(earthquakes) | ||
|
||
plot_usmap() + | ||
geom_point(data = eq_transformed, aes(x = lon.1, y = lat.1, size = mag), | ||
color = "red", alpha = 0.25) + | ||
labs(title = "US Earthquakes", | ||
subtitle = "Source: USGS, Jan 1 to Jun 30 2019", | ||
size = "Magnitude") + | ||
theme(legend.position = "right") | ||
|
||
## ---- fig.align='center', fig.width=8, fig.height=5, message=FALSE, warning=FALSE---- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
cities_t <- usmap_transform(citypop) | ||
|
||
plot_usmap(fill = "yellow", alpha = 0.25) + | ||
ggrepel::geom_label_repel(data = cities_t, | ||
aes(x = lon.1, y = lat.1, label = most_populous_city), | ||
size = 3, alpha = 0.8, | ||
label.r = unit(0.5, "lines"), label.size = 0.5, | ||
segment.color = "red", segment.size = 1, | ||
seed = 1002) + | ||
geom_point(data = cities_t, | ||
aes(x = lon.1, y = lat.1, size = city_pop), | ||
color = "purple", alpha = 0.5) + | ||
scale_size_continuous(range = c(1, 16), | ||
label = scales::comma) + | ||
labs(title = "Most Populous City in Each US State", | ||
subtitle = "Source: US Census 2010", | ||
size = "City Population") + | ||
theme(legend.position = "right") | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
## ----setup, include = FALSE--------------------------------------------------- | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
|
||
## ---- fig.align='center', fig.width=7----------------------------------------- | ||
usmap::plot_usmap() | ||
|
||
## ---- fig.align='center', fig.width=7----------------------------------------- | ||
usmap::plot_usmap(regions = "counties") | ||
|
||
## ---- eval = FALSE------------------------------------------------------------ | ||
# states_df <- usmap::us_map() | ||
# counties_df <- usmap::us_map(regions = "counties") | ||
|
||
## ----------------------------------------------------------------------------- | ||
# Get FIPS code for a state | ||
usmap::fips(state = "MA") | ||
usmap::fips(state = "Massachusetts") | ||
|
||
# Get FIPS code for a county | ||
usmap::fips(state = "NJ", county = "Bergen") | ||
usmap::fips(state = "CA", county = "Orange County") | ||
|
||
# The parameters are NOT case sensitive! | ||
usmap::fips(state = "ca", county = "oRanGe cOUNty") | ||
|
||
## ----------------------------------------------------------------------------- | ||
usmap::fips_info(c("30", "33", "34")) | ||
|
||
## ----------------------------------------------------------------------------- | ||
usmap::fips_info(c("01001", "01003", "01005", "01007")) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
## ----setup, include = FALSE--------------------------------------------------- | ||
knitr::opts_chunk$set( | ||
collapse = TRUE, | ||
comment = "#>" | ||
) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
plot_usmap(regions = "counties") + | ||
labs(title = "US Counties", | ||
subtitle = "This is a blank map of the counties of the United States.") + | ||
theme(panel.background = element_rect(color = "black", fill = "lightblue")) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
plot_usmap(include = c("CA", "ID", "NV", "OR", "WA")) + | ||
labs(title = "Western US States", | ||
subtitle = "These are the states in the Pacific Timezone.") | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
plot_usmap(data = statepop, values = "pop_2015", color = "red") + | ||
scale_fill_continuous(name = "Population (2015)", label = scales::comma) + | ||
theme(legend.position = "right") | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
plot_usmap(data = statepop, values = "pop_2015", color = "red") + | ||
scale_fill_continuous( | ||
low = "white", high = "red", name = "Population (2015)", label = scales::comma | ||
) + theme(legend.position = "right") | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
library(usmap) | ||
library(ggplot2) | ||
|
||
plot_usmap( | ||
data = statepop, values = "pop_2015", include = c("CA", "ID", "NV", "OR", "WA"), color = "red" | ||
) + | ||
scale_fill_continuous( | ||
low = "white", high = "red", name = "Population (2015)", label = scales::comma | ||
) + | ||
labs(title = "Western US States", subtitle = "These are the states in the Pacific Timezone.") + | ||
theme(legend.position = "right") | ||
|
||
## ---- fig.show='hide', message=FALSE, warning=FALSE--------------------------- | ||
df <- data.frame( | ||
fips = c("02", "01", "05", "04"), | ||
values = c(14, 18, 19, 8) | ||
) | ||
|
||
plot_usmap(data = df) | ||
|
||
## ---- fig.show='hide', message=FALSE, warning=FALSE--------------------------- | ||
df <- data.frame( | ||
fips = c("02", "01", "05", "04"), | ||
population = c(14, 18, 19, 8) | ||
) | ||
|
||
plot_usmap(data = df, values = "population") | ||
|
||
## ---- fig.show='hide', message=FALSE, warning=FALSE--------------------------- | ||
df <- data.frame( | ||
state = c("AL", "Alaska", "AR", "AZ"), | ||
values = c(14, 18, 19, 8) | ||
) | ||
|
||
plot_usmap(data = df) | ||
|
||
## ---- fig.show='hide', message=FALSE, warning=FALSE--------------------------- | ||
df <- data.frame( | ||
fips = c("10001", "10003", "10005"), | ||
values = c(93, 98, 41) | ||
) | ||
|
||
plot_usmap(data = df) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
usmap::plot_usmap(include = .south_region) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
usmap::plot_usmap(include = .east_south_central) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
usmap::plot_usmap(include = .south_region, exclude = .east_south_central) | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
usmap::plot_usmap("counties", | ||
include = c(.south_region, "IA"), | ||
exclude = c(.east_south_central, "12")) # 12 = FL | ||
|
||
## ---- fig.align='center', fig.width=7, message=FALSE, warning=FALSE----------- | ||
usmap::plot_usmap("counties", fill = "yellow", alpha = 0.25, | ||
# 06065 = Riverside County, CA | ||
include = c(.south_region, "IA", "06065"), | ||
# 12 = FL, 48141 = El Paso County, TX | ||
exclude = c(.east_south_central, "12", "48141")) | ||
|
||
## ----------------------------------------------------------------------------- | ||
.new_england | ||
.mid_atlantic | ||
.east_north_central | ||
.west_north_central | ||
.south_atlantic | ||
.east_south_central | ||
.west_south_central | ||
.mountain | ||
.pacific | ||
|
||
## ----------------------------------------------------------------------------- | ||
.northeast_region # c(.new_england, .mid_atlantic) | ||
.north_central_region # c(.east_north_central, .west_north_central) | ||
.midwest_region # .north_central_region (renamed in June 1984) | ||
.south_region # c(.south_atlantic, .east_south_central, .west_south_central) | ||
.west_region # c(.mountain, .pacific) | ||
|
||
## ----------------------------------------------------------------------------- | ||
str(usmap::us_map()) | ||
|
||
## ----------------------------------------------------------------------------- | ||
str(usmap::us_map(regions = "counties")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.