knitr::opts_chunk$set(echo = TRUE, eval = TRUE) library(knitr) set.seed(12314159)
$\renewcommand{\tr}[1]{{#1}^{\mkern-1.5mu\mathsf{T}}}$ $\renewcommand{\ve}[1]{\mathbf{#1}}$ $\renewcommand{\sv}[1]{\boldsymbol{#1}}$ $\renewcommand{\pop}[1]{\mathcal{#1}}$ $\renewcommand{\samp}[1]{\mathcal{#1}}$ $\renewcommand{\imply}{\Longrightarrow}$ $\renewcommand{\given}{~\vert~}$ $\renewcommand{\suchthat}{~:~}$ $\renewcommand{\widebar}[1]{\overline{#1}}$ $\renewcommand{\wig}[1]{\tilde{#1}}$ $\renewcommand{\bigwig}[1]{\widetilde{#1}}$ $\renewcommand{\field}[1]{\mathbb{#1}}$ $\renewcommand{\Reals}{\field{R}}$ $\renewcommand{\abs}[1]{\left\lvert ~{#1} ~\right\rvert}$ $\renewcommand{\size}[1]{\left\lvert {#1} \right\rvert}$ $\renewcommand{\tr}[1]{{#1}^{\mkern-1.5mu\mathsf{T}}}$ $\renewcommand{\norm}[1]{\left|\left|{#1}\right|\right|}$ $\renewcommand{\intersect}{\cap}$ $\renewcommand{\union}{\cup}$
In this vignette, we apply the functions l_micromaps()
and l_ccmaps()
to explore lung and bronchus cancer mortality in the United States.
library(loon.micromaps)
There are many sources for U.S. state polygons, one of which is the micromap
R package. It is a "SpatialPolygonsDataFrame" object, with simplified edges, the states of Alaska and Hawaii transformed into insets next to the contiguous states, and Washington DC as its own separate polygon. It can be accessed using
data('USstates', package = 'micromap')
USstates
, when plotted, looks like Figure \ref{fig:fig6}.
```rU.S. States"} class(USstates)
names(USstates)
plot(USstates, main = "U.S. states")
## U.S. lung and bronchus cancer mortality data In addition to the lung and bronchus cancer mortality rate by state [@CDCa], we collected two other variables of interest - the annual income per capita [@BEA] and annual average of daily outdoor fine particulate matter levels [@CDCb], measured in $\mu g / m^3$, averaged over the years 2009 - 2011. ```r data('us_lungmort_2009_2011') str(us_lungmort_2009_2011)
Here, income
(income per capita) is measured in $1,000's.
To construct a micromap based on these values, the data of interest must be merged with the spatial data:
USstates@data <- merge(USstates@data, us_lungmort_2009_2011, all.x = T, all.y = F, by.y = 'state.abbr', by.x = 'ST') names(USstates@data)
The following creates the linked micromaps display with variables in us_lungmort_2009_2011
, with the result shown in Figure \ref{fig:fig7}:
mm <- l_micromaps(lab.label = 'States', spdf = USstates, variables = list(id.var = 'ST_NAME', grouping.var = list(name = 'lung_bronch_death'), var2 = list(name = 'pm25', label = 'Fine Particulate Matter Level'), var3 = list(name = 'income', label = 'Income per Capita')), linkingGroup = 'States', sync = 'push', spacing = 'equal', itemLabel = as.character(USstates@data$ST_NAME), showItemLabels = TRUE, otry = 20)
```rU.S. Lung and Bronchus Cancer Mortality, Linked Micromaps", out.width = "100%"} knitr::include_graphics("figures/us_micromaps.png")
## Conditioned choropleth maps The following creates the conditioned choropleth maps display with variables in ```us_lungmort_2009_2011```, optimized for $R^2$. Figure \ref{fig:fig8} shows the resulting display. ```r cc <- l_ccmaps(spdf = USstates, title = 'CCmaps', respvar = 'lung_bronch_death', respvar.lab = 'Lung & Bronchus Cancer Death Rate', cond1var = 'pm25', cond1var.lab = 'Fine Particulate Matter Level', cond2var = 'income', cond2var.lab = 'Income per Capita', respscale = 'actual', cond1scale = 'actual', cond2scale = 'actual', optimize = TRUE)
rU.S. Lung and Bronchus Cancer Mortality, Conditioned Chorpleth Maps", out.width = "100%"}
knitr::include_graphics("figures/us_ccmaps.png")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.