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 show how to use l_micromaps() to construct interactive micromaps in loon (as implemented in the package loon.micromaps).

library(loon.micromaps)

l_ccmaps()

Conditioned choropleth maps can be seen as a simple fitted model on the response variable [@carr2010visualizing] (pct_immigrants in this example). The $R^2$ statistic is defined as:

[ R^2 = \frac{\sum_{i=1}^n (\textrm{model value}i - \textrm{grand mean})^2}{\sum{i=1}^n (\textrm{actual value}_i - \textrm{grand mean})^2}\textrm{ ,} ]

where actual value is the observed data, grand mean is the overall mean for the response variable, and model value is the mean of the response value in each of the panels. It can be understood as the percentage variability in the response explained by panel membership. A grid search is conducted to find a good fit, although it does not guarantee a global optimum and is intended as a starting point for your data exploration.

The following creates the conditioned choropleth maps display, optimized for $R^2$. Again, there are two inspectors - loon inspector and the custom inspector for the conditioned choropleth maps display. The result is shown in Figure \ref{fig:fig5}.

cc <- l_ccmaps(spdf = cd_SWOntario_2006,
               respvar = 'pct_immigrants', respvar.lab = '% Immigrant Population',
               cond1var = 'bachelor_above', cond1var.lab = '% with Bachelor Education',
               cond2var = 'pop_density', cond2var.lab = 'Population Density',
               seg1col = 'yellow', seg3col = 'orange',
               respscale = 'log', cond1scale = 'actual', cond2scale = 'log',
               optimize = TRUE, otry = 20)

rSouth Western Ontario Demographics, Conditioned Choropleth Maps", fig.align = "center", out.width = "100%"} knitr::include_graphics("figures/canada_ccmaps.png")

Note that when optimize = TRUE, the code will take some time to run depending on the value of otry.

The handles on the three sliders can be shifted left and right to adjust the colors and panel membership, with the $R^2$ value updated accordingly. The sliders can be drawn in three scales: actual/unchanged, percentile and logarithmic (see inspector). Note that the logarithmic scale can only be used when all values are above zero.



x249wang/loon.micromaps documentation built on May 10, 2019, 8:30 a.m.