forked from trulia/choroplethr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
county_choropleth.Rd
73 lines (62 loc) · 2.79 KB
/
county_choropleth.Rd
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
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/county.R
\name{county_choropleth}
\alias{county_choropleth}
\title{Create a choropleth of US Counties}
\usage{
county_choropleth(df, title = "", legend = "", num_colors = 7,
state_zoom = NULL, county_zoom = NULL, reference_map = FALSE)
}
\arguments{
\item{df}{A data.frame with a column named "region" and a column named "value". Elements in
the "region" column must exactly match how regions are named in the "region" column in county.map.}
\item{title}{An optional title for the map.}
\item{legend}{An optional name for the legend.}
\item{num_colors}{The number of colors on the map. A value of 1
will use a continuous scale. A value in [2, 9] will use that many colors.}
\item{state_zoom}{An optional vector of states to zoom in on. Elements of this vector must exactly
match the names of states as they appear in the "region" column of ?state.regions.}
\item{county_zoom}{An optional vector of counties to zoom in on. Elements of this vector must exactly
match the names of counties as they appear in the "region" column of ?county.regions.}
\item{reference_map}{If true, render the choropleth over a reference map from Google Maps.}
}
\description{
The map used is county.map in the choroplethrMaps package. See country.regions
in the choroplethrMaps package for an object which can help you coerce your regions
into the required format.
}
\examples{
\dontrun{
# default parameters
data(df_pop_county)
county_choropleth(df_pop_county,
title = "US 2012 County Population Estimates",
legend = "Population")
# zoom in on california and add a reference map
county_choropleth(df_pop_county,
title = "California County Population Estimates",
legend = "Population",
state_zoom = "california",
reference_map = TRUE)
# continuous scale
data(df_pop_county)
county_choropleth(df_pop_county,
title = "US 2012 County Population Estimates",
legend = "Population",
num_colors = 1,
state_zoom = c("california", "oregon", "washington"))
library(dplyr)
library(choroplethrMaps)
data(county.regions)
# show the population of the 5 counties (boroughs) that make up New York City
nyc_county_names = c("kings", "bronx", "new york", "queens", "richmond")
nyc_county_fips = county.regions \%>\%
filter(state.name == "new york" & county.name \%in\% nyc_county_names) \%>\%
select(region)
county_choropleth(df_pop_county,
title = "Population of Counties in New York City",
legend = "Population",
num_colors = 1,
county_zoom = nyc_county_fips$region)
}
}