---
title: "Dr. Hu's R Workshop"
output: 
  learnr::tutorial:
    progressive: true
    allow_skip: true
    css: css/styles.css
runtime: shiny_prerendered
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)

library(learnr)
library(ggthemes)
library(scales)
library(gt)
library(modelsummary)
library(dotwhisker)
library(interplot)
library(likert)
library(tidyverse)
library(gapminder)


# Functions preload
set.seed(114)

# Data of incubation

incubation_data = data.frame(
  sname = factor(
    c(
      "Minimum\n0%",
      "2.5%",
      "Median\n50%",
      "Average",
      "97.5%",
      "Maximum\n100%"
    ),
    levels = c(
      "Minimum\n0%",
      "2.5%",
      "Median\n50%",
      "Average",
      "97.5%",
      "Maximum\n100%"
    ),
    ordered = TRUE
  ),
  svalue = c(0, 2.2, 5.1, 5.5, 11.5, 14),
  stext = c(
    "\n(Unknown)",
    "\n2.2 days",
    "\n5.1 days",
    "\n5.5 days",
    "\n11.5 days",
    "\n14 days"
  )
)

## Data of cfr

age_groups <-
  c("≤9",
    "10-19",
    "20-29",
    "30-39",
    "40-49",
    "50-59",
    "60-69",
    "70-79",
    "≥80")
cfr_china <-
  data.frame(
    age = factor(age_groups, levels = age_groups, ordered = TRUE),
    deaths = c(0, 1, 7, 18, 38, 130, 309, 312, 208),
    cases = c(416, 549, 3619, 7600, 8571, 10008, 8583, 3918, 1408),
    cfr = 0.01 * c(0, 0.18, 0.19, 0.23, 0.44, 1.3, 3.6, 8., 14.8)
  )

## data of liker

input <- ("
  Mask    Bleach  WashHand
  3       2       4
  5       4       4
  4       2       4
  4       2       4
  4       1       5
  4       2       3
  4       3       5
  4       2       4
  5       2       4
  5       3       3
")

df_likert <- read.table(textConnection(input), header = TRUE)

df_likert$Mask <- factor(df_likert$Mask,
                   levels = c("1", "2", "3", "4", "5"),
                   ordered = TRUE)

df_likert$Bleach <- factor(df_likert$Bleach,
                     levels = c("1", "2", "3", "4", "5"),
                     ordered = TRUE)

df_likert$WashHand <- factor(df_likert$WashHand,
                     levels = c("1", "2", "3", "4", "5"),
                     ordered = TRUE)

m1 <- lm(mpg ~ cyl + hp + wt, data = mtcars)
m2 <- lm(mpg ~ cyl + hp + wt + hp, data = mtcars)
m3 <- lm(mpg ~ cyl + hp + wt + hp + am, data = mtcars)

m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
```

## A Picture Worths a Thousand Words

<img src='https://raw.githubusercontent.com/sammo3182/drhur/master/inst/tutorials/visualizing/images/picThanWords.jpg' width = '100%'>

## When You Become a Professional Visualizer...

### Networks

<div class="centered">
<img src="https://raw.githubusercontent.com/sammo3182/drhur/master/inst/tutorials/visualizing/images/hiveplot.png" height="450"/>
</div>

### Maps

<div class="center">
<img src='https://raw.githubusercontent.com/sammo3182/drhur/master/inst/tutorials/visualizing/images/ggmap.png' height="600"/>
</div>

### Interactive plots

<div class="center">
<img src="https://raw.githubusercontent.com/sammo3182/drhur/master/inst/tutorials/visualizing/images/interactive3D.gif" height="550"/>
</div>

## Skill

1. Statistics
    + Descriptive
    + Post-analysis
1. Network
    + Diagram ([`DiagrammeR`](https://rich-iannone.github.io/DiagrammeR/docs.html), [`semPlot`](http://sachaepskamp.com/semPlot/examples))
1. Map



## Learning with Three Examples

1. Gapminder 2007 (Point plot)
1. COVID-19 Case Fatality Rate (Bar plot)
1. COVID-19 Incubation Time (Fan plot)

```{r goal-plots, results="hide", out.width="100%", echo=FALSE}
if (!require(ggplot2)) install.packages("ggplot2")
if (!require(scales)) install.packages("scales")
if (!require(ggthemes)) install.packages("ggthemes")
if (!require(gapminder)) install.packages("gapminder")

library(ggplot2) # major function
library(ggthemes) # outlook
library(scales) # scale of the axes
library(gapminder) # data

gapminder_2007 <- filter(gapminder, year == 2007)

ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp, size = pop, 
                 color = continent), 
             alpha = 0.5)

ggplot(cfr_china, aes(x=age, y=cfr, group=1)) +
  geom_line() +
  geom_hline(yintercept = 0.01 * 2.3, linetype="dashed", alpha=0.5) +
  geom_bar(aes(width=cases/10000, fill=age), stat = "identity", position = "identity") +
  geom_text(aes(label=paste0(cfr*100,"%")), family="Palatino", size=3, nudge_y = 0.04) +
  geom_text(aes(label=paste0("(",deaths,"/",cases,")")), family="Palatino", size=3, nudge_y = 0.03) +
  scale_y_continuous(labels = percent) +
  scale_fill_tableau(palette = "Classic 10 Medium") +
  labs(title = "COVID-19 Case Fatality Rate (CFR) by Age Groups",
       subtitle = "Among 44,672 confirmed cases in China through February 11\nOverall CFR = 2.3% (dotted line)",
       x = "Age Group", y = NULL,
       caption = "Source: Characteristics of and Important Lessons From the Coronavirus Disease 2019 (COVID-19) Outbreak in China:\nSummary of a Report of 72314 Cases From the Chinese Center for Disease Control and Prevention. Wu Z, McGoogan JM. JAMA. 2020\nhttps://jamanetwork.com/journals/jama/fullarticle/2762130 and http://weekly.chinacdc.cn/en/article/id/e53946e2-c6c4-41e9-9a9b-fea8db1a8f51") +
  theme_minimal(base_size = 14, base_family = "Palatino") +
  theme(plot.caption = element_text(face = "italic", size=6),
        legend.position = "none")


ggplot(incubation_data, aes(ymax = svalue, ymin = 0, xmax = 2, xmin = 1, fill = sname)) +
  geom_rect(aes(ymax=14, ymin=0, xmax=2, xmin=1), fill ="#ece8bd") +
  geom_rect() + 
  coord_polar(theta = "y",start=-pi/2) + 
  xlim(c(0, 2)) + ylim(c(0,28)) +
  scale_fill_few(palette = "Medium") +
  scale_color_few(palette = "Medium") +
  geom_text(aes(x = 0, y = 0, label=stext, colour=sname), size=4, family="Palatino") +
  facet_wrap(~sname, ncol = 3) +
  guides(fill=FALSE, colour=FALSE) +
  labs(title="COVID-19 Incubation Time", 
       subtitle = "Time before infected person becomes symptomatic\n (percentiles and mean) ",
       caption = "Source: COVID-19 Incubation Period: An Update. Stephen G. Baum, MD\n reviewing Lauer SA et al. Ann Intern Med 2020 Mar 10\nhttps://www.jwatch.org/na51083/2020/03/13/covid-19-incubation-period-update", 
       x=NULL, y=NULL) +
  theme_tufte(ticks = FALSE, base_size = 12, base_family = "Palatino") +
  theme(axis.text = element_blank(),
        plot.caption = element_text(face = "italic", size=6),
        strip.text = element_text(size = 12))
```

## Abilities You'll Achieve

1. Draw basic and `ggplot` charts.
1. Read complex `ggplot` codes.


## R's Visualization System

* Basic plots: `plot()`.
* Lattice plots: e.g., `ggplot()`.
* Interactive plots: `shiny()` (Not for today)

## Basic Plot

Pro:

* Embedded in R
* Good tool for <span style="color:purple">data exploration</span>. 
* <span style="color:purple">Spatial</span> analysis and <span style="color:purple">3-D</span> plots.

Con:

* Not very delicate
* Not very flexible

### Example

```{r basePlot, exercise = TRUE}
hist(mtcars$mpg)
```

### Saving the output

* Compatible format:`.jpg`, `.png`, `.wmf`, `.pdf`, `.bmp`, and `postscript`.
* Process: 
    1. call the graphic device
    2. plot
    3. close the device

```{r saving, eval = F}
png("<working directory>/histgraph.png")
hist(mtcars$mpg)
dev.off()
```

## `ggplot`

Built based on Leland Wilkinson's *Grammar of Graphics*.

* To use `ggplot` function, you need another `tidyverse` package: `ggplot2`.


## Two Stuffs You Need to Know Ahead

* `mapping`: Aesthetic (`aes`, `alpha`)---color, shape, size
    + Properties that can be perceived in the graph.
    + Each aesthetic can be mapped to a variable, or set to a constant value
* `geom_`: Geometric---points, lines, bars
    + Over forty types

<img src='https://raw.githubusercontent.com/sammo3182/drhur/master/inst/tutorials/visualizing/images/ggplot_geom.png' width = '100%'>

## Primary Template

```{r basic, eval = FALSE}
ggplot(___) + 
  geom_point(
    mapping = aes(x = ___, y = ___, 
                  color = ___, 
                  size  = ___),
    alpha  = ___
  )
```

## Example: Aesthetic Attributes

###

```{r pointGoal,echo=FALSE}
library(gapminder)

gapminder_2007 <- filter(gapminder, year == 2007)

ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp, size = pop, 
                 color = continent), 
             alpha = 0.5)
```


### Step by Step

```{r point, exercise = TRUE}
library(gapminder)

gapminder_2007 <- filter(gapminder, year == 2007)

ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp))
```

```{r point-solution}
# Color adjustment
ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp,
                 color = continent))

ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp,
                 color = pop))

# Size adjustment
ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp,
                 size = pop)) + 
  scale_size_area(max_size = 10)

# Transparency adjustment
ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp, size = pop), 
             alpha = 0.5)

# Combo

ggplot(gapminder_2007) + 
  geom_point(aes(x = gdpPercap, y = lifeExp, size = pop, 
                 color = continent), 
             alpha = 0.5)
```


## Example: Geomatric Layers 

###

```{r cfr-df, echo = FALSE}
# Case Fatality Rate

cfr_china
```

###

```{r cfr-plot, echo = FALSE}
if (!require(ggplot2)) install.packages("ggplot2")
if (!require(scales)) install.packages("scales")
if (!require(ggthemes)) install.packages("ggthemes")

library(ggplot2)
library(scales)
library(ggthemes)

ggplot(cfr_china, aes(x=age, y=cfr, group=1)) +
  geom_line() +
  geom_hline(yintercept = 0.01 * 2.3, linetype="dashed", alpha=0.5) +
  geom_bar(aes(width=cases/10000, fill=age), stat = "identity", position = "identity") +
  geom_text(aes(label=paste0(cfr*100,"%")), family="Palatino", size=3, nudge_y = 0.04) +
  geom_text(aes(label=paste0("(",deaths,"/",cases,")")), family="Palatino", size=3, nudge_y = 0.03) +
  scale_y_continuous(labels = percent) +
  scale_fill_tableau(palette = "Classic 10 Medium") +
  labs(title = "COVID-19 Case Fatality Rate (CFR) by Age Groups",
       subtitle = "Among 44,672 confirmed cases in China through February 11\nOverall CFR = 2.3% (dotted line)",
       x = "Age Group", y = NULL,
       caption = "Source: Characteristics of and Important Lessons From the Coronavirus Disease 2019 (COVID-19) Outbreak in China:\nSummary of a Report of 72314 Cases From the Chinese Center for Disease Control and Prevention. Wu Z, McGoogan JM. JAMA. 2020\nhttps://jamanetwork.com/journals/jama/fullarticle/2762130 and http://weekly.chinacdc.cn/en/article/id/e53946e2-c6c4-41e9-9a9b-fea8db1a8f51") +
  theme_minimal(base_size = 14, base_family = "Palatino") +
  theme(plot.caption = element_text(face = "italic", size=6),
        legend.position = "none")
```

### Step by Step

```{r steps, exercise = TRUE}
if (!require(ggplot2)) install.packages("ggplot2")
if (!require(scales)) install.packages("scales")
if (!require(ggthemes)) install.packages("ggthemes")

library(ggplot2)
library(scales)
library(ggthemes)

ggplot(data = cfr_china,
       aes(x = age, y = cfr, group = 1))
```

```{r steps-solution}
ggplot(data = cfr_china,
       aes(x = age, y = cfr, group = 1)) + 
  geom_bar(aes(width = cases / 10000, fill = age),
           stat = "identity",
           position = "identity") +
  geom_hline(yintercept = 0.01 * 2.3,
             linetype = "dashed",
             alpha = 0.5) +
  geom_line() +
  geom_text(
    aes(label = paste0(cfr * 100, "%")),
    family = "Palatino",
    size = 3,
    nudge_y = 0.04
  ) +
  geom_text(
    aes(label = paste0("(", deaths, "/", cases, ")")),
    family = "Palatino",
    size = 3,
    nudge_y = 0.03
  ) +
  scale_y_continuous(labels = percent) +
  scale_fill_tableau(palette = "Classic 10 Medium") + 
  labs(
    title = "COVID-19 Case Fatality Rate (CFR) by Age Groups",
    subtitle = "Among 44,672 confirmed cases in China through February 11\nOverall CFR = 2.3% (dotted line)",
    x = "Age Group",
    y = NULL,
    caption = "Source: Characteristics of and Important Lessons From the Coronavirus Disease 2019 (COVID-19) Outbreak in China:\nSummary of a Report of 72314 Cases From the Chinese Center for Disease Control and Prevention. Wu Z, McGoogan JM. JAMA. 2020\nhttps://jamanetwork.com/journals/jama/fullarticle/2762130 and http://weekly.chinacdc.cn/en/article/id/e53946e2-c6c4-41e9-9a9b-fea8db1a8f51"
  ) +
  theme_minimal(base_size = 14, base_family = "Palatino") +
  theme(plot.caption = element_text(face = "italic", size = 6),
        legend.position = "none")
```

###

* `data`: The data that you want to visualize
* `aes`: Aesthetic mappings
* `geoms`: Geometric objects 
* `labs`: 
    + `title, subtitle`: Titles
    + `x, y`: Axis labels
    + `caption`: Notes
+ `stats`: Statistics transformations
+ `scales`: relate the data to the aesthetic
    + `coord`: a coordinate system that describes how data coordinates are
mapped to the plane of the graphic.
    + `facet`: a faceting specification describes how to break up the data into sets.
* `theme`: background


### Saving the output

* `ggsave(<plot project>, "<name + type>")`:
    + When the `<plot project>` is omitted, R will save the last presented plot. 
    + There are additional arguments which users can use to adjust the size, path, scale, etc.
    
```{r save, eval = FALSE}
ggsave("cfr.png")
```

## COVID-19 Incubation Time

###

```{r incubation-df, echo = FALSE}
incubation_data %>% 
  mutate(sname = c("0%", "2.5%", "50%", "Average", "97.5%", "100%"),
         stext = str_sub(stext, start = 2))
```

```{r incubation-plot, echo = FALSE}
ggplot(incubation_data, aes(ymax = svalue, ymin = 0, xmax = 2, xmin = 1, fill = sname)) +
  geom_rect(aes(ymax=14, ymin=0, xmax=2, xmin=1), fill ="#ece8bd") +
  geom_rect() + 
  coord_polar(theta = "y",start=-pi/2) + 
  xlim(c(0, 2)) + ylim(c(0,28)) +
  scale_fill_few(palette = "Medium") +
  scale_color_few(palette = "Medium") +
  geom_text(aes(x = 0, y = 0, label=stext, colour=sname), size=4, family="Palatino") +
  facet_wrap(~sname, ncol = 3) +
  guides(fill=FALSE, colour=FALSE) + # removed the legend
  labs(title="COVID-19 Incubation Time", 
       subtitle = "Time before infected person becomes symptomatic\n(percentiles and mean) ",
       caption = "Source: COVID-19 Incubation Period: An Update. Stephen G. Baum, MD\n reviewing Lauer SA et al. Ann Intern Med 2020 Mar 10\nhttps://www.jwatch.org/na51083/2020/03/13/covid-19-incubation-period-update", 
       x=NULL, y=NULL) +
  theme_tufte(ticks = FALSE, base_size = 12, base_family = "Palatino") +
  theme(axis.text = element_blank(),
        plot.caption = element_text(face = "italic", size=6),
        strip.text = element_text(size = 12))
```

### Steps

```{r incubation, exercise = TRUE}
ggplot(incubation_data,
       aes(
         ymax = svalue,
         ymin = 0,
         xmax = 2,
         xmin = 1,
         fill = sname
       )) 
```


```{r incubation-solution}
ggplot(incubation_data,
       aes(
         ymax = svalue,
         ymin = 0,
         xmax = 2,
         xmin = 1,
         fill = sname
       )) +
  geom_rect(aes(
    ymax = 14,
    ymin = 0,
    xmax = 2,
    xmin = 1
  ), fill = "#ece8bd") +
  geom_rect() +
  coord_polar(theta = "y", start = -pi / 2) +
  xlim(c(0, 2)) + ylim(c(0, 28)) +
  scale_fill_few(palette = "Medium") +
  scale_color_few(palette = "Medium") +
  geom_text(aes(
    x = 0,
    y = 0,
    label = stext,
    colour = sname
  ),
  size = 4,
  family = "Palatino") +
  facet_wrap( ~ sname, ncol = 3) +
  guides(fill = FALSE, colour = FALSE) +
  labs(
    title = "COVID-19 Incubation Time",
    subtitle = "Time before infected person becomes symptomatic\n(percentiles and mean) ",
    caption = "Source: COVID-19 Incubation Period: An Update. Stephen G. Baum, MD\n reviewing Lauer SA et al. Ann Intern Med 2020 Mar 10\nhttps://www.jwatch.org/na51083/2020/03/13/covid-19-incubation-period-update",
    x = NULL,
    y = NULL
  ) +
  theme_tufte(ticks = FALSE,
              base_size = 12,
              base_family = "Palatino") +
  theme(
    axis.text = element_blank(),
    plot.caption = element_text(face = "italic", size = 6),
    strip.text = element_text(size = 12)
  )
```



## Post-Analysis Visualization

* Likert responses
* Coefficients
* Interactions
* Map

### Likert-Scale Index

```{r likert, exercise = TRUE}
df_likert

if (!require(likert)) install.packages("likert")
library(likert)

likert(df_likert) %>%
  plot(type = "bar")
```

```{r likert-solution}
likert(df_likert) %>%
  plot(
    type = "heat",
    low.color = "white",
    high.color = "blue",
    text.color = "black",
    text.size = 4,
    wrap = 50
  )

likert(df_likert) %>%
  plot(type = "density",
       facet = TRUE,
       bw = 0.5)
```

## Regression Results

### Coefficient visualization

`dotwhisker` ![](http://cranlogs.r-pkg.org/badges/grand-total/dotwhisker)

```{r dotwhisker, exercise = TRUE}
m1 <- lm(mpg ~ cyl + hp + wt, data = mtcars)
```

```{r dotwhisker-solution}
if (!require(dotwhisker)) install.packages("dotwhisker")
library(dotwhisker)

dwplot(m1)
```


### Multiple models

```{r dwMulti, exercise = TRUE}
m2 <- lm(mpg ~ cyl + hp + wt + hp, data = mtcars)
m3 <- lm(mpg ~ cyl + hp + wt + hp + am, data = mtcars)

dwplot(list(m1, m2, m3))
```

```{r dwMulti-solution}
dwplot(list(m1, m2, m3)) %>%
  relabel_predictors(
    c(
      wt = "Weight",
      cyl = "Cylinders",
      disp = "Displacement",
      hp = "Horsepower",
      gear = "Gears",
      am = "Manual"
    )
  ) +
  theme_bw() + xlab("Coefficient Estimate") + ylab("") +
  geom_vline(xintercept = 0,
             colour = "grey60",
             linetype = 2) +
  ggtitle("Predicting Gas Mileage") +
  theme(
    plot.title = element_text(face = "bold"),
    legend.justification = c(0, 0),
    legend.position = c(0, 0),
    legend.background = element_rect(colour = "grey80"),
    legend.title = element_blank()
  ) 
```


### Comparing in their own scales.

```{r smallMultiple, exercise = TRUE}
small_multiple(list(m1, m2, m3)) +
  ylab("Coefficient Estimate") +
  geom_hline(yintercept = 0,
             colour = "grey60",
             linetype = 2) +
  ggtitle("Predicting Gas Mileage") +
  theme(
    plot.title = element_text(face = "bold"),
    legend.position = "none",
    axis.text.x  = element_text(angle = 60, hjust = 1)
  ) 
```


## Moderation Effects

`interplot` ![](http://cranlogs.r-pkg.org/badges/grand-total/interplot)

Visualizing the changes in the coefficient of one variable in a two-way interaction term conditional on the value of the other included variable.

* You can't correctly explain interactions with table!
    + Model: $$Y = \beta_0 + \beta_1X + \beta_2Z + \beta_3X\times Z + \varepsilon.$$
    + Effect: $$\frac{\partial Y}{\partial X} = \beta_1 + \beta_3Z.$$
    + Standard error: $$\hat{\sigma}_{\frac{\partial Y}{\partial X}} = \sqrt{var(\hat{\beta_1}) + Z^2var(\hat{\beta_3}) + 2Zcov(\hat{\beta_1}, \hat{\beta_3})}.$$

* How can you tell if the change is significant?
    + Most precise way: calculate the difference between two mean with SEs.
    + Most convenient way: visualizing it

### Plotting moderation

```{r interact, exercise = TRUE}
m_cyl <- lm(mpg ~ wt * cyl, data = mtcars)
summary(m_cyl)
```

```{r interact-solution}
if (!require(interplot)) install.packages("interplot")
library(interplot)

interplot(m = m_cyl, var1 = "cyl", var2 = "wt")
interplot(m = m_cyl, var1 = "wt", var2 = "cyl")
```

### Significant?

```{r interHist}
interplot(m = m_cyl, var1 = "cyl", var2 = "wt", hist = TRUE) +
    geom_hline(yintercept = 0, linetype = "dashed")
```

### Category comparison

```{r interFactor}
mtcars$gear <- factor(mtcars$gear)
m_gear <- lm(mpg ~ gear * wt, data = mtcars)

interplot(m = m_gear, var1 = "wt", var2 = "gear")
```


## Network Visualization

```{r network}
if (!require(network)) install.packages("network")
if (!require(sna)) install.packages("sna")

library(network)
library(sna)
n <- network(rgraph(10, tprob = 0.2), directed = FALSE)

n %v% "family" <- sample(letters[1:3], 10, replace = TRUE)
n %v% "importance" <- sample(1:3, 10, replace = TRUE)

e <- network.edgecount(n)
set.edge.attribute(n, "type", sample(letters[24:26], e, replace = TRUE))
set.edge.attribute(n, "day", sample(1:3, e, replace = TRUE))

if (!require(ggnetwork)) install.packages("ggnetwork")
library(ggnetwork)

ggplot(n, aes(x = x, y = y, xend = xend, yend = yend)) +
  geom_edges(aes(linetype = type), color = "grey50") +
  geom_nodes(aes(color = family, size = importance)) +
  theme_blank()
```

## Geographic Visualization

```{r map, message=FALSE, cache=TRUE}
if (!require(ggmap)) install.packages("ggmap")
library(ggmap)

china <- c(left = 72, bottom = 0, right = 135, top = 52)

get_stamenmap(china, zoom = 5, maptype = "toner-lite") %>% 
  ggmap() 
```

More information about mapping China, see Jie Zhang's [post](http://www.easycharts.club/article/11). 

## Bonus: Tables

###

```{r modeltable, exercise = TRUE}
summary(m1); summary(m2); summary(m3)

if (!require(gt)) install.packages("gt")
if (!require(modelsummary)) install.packages("modelsummary")
library(modelsummary)
library(gt)
```

```{r modeltable-solution}
msummary(list(m1, m2, m3),
         stars = TRUE,
         title =  gt::md('This is *the* title'),
         subtitle = 'And a subtitle',
         notes = list('A first note', gt::md('A **bold** note'))) %>%
  tab_style(style = cell_fill(color = "lightcyan"),
			  locations = cells_body(columns = vars(`Model 2`), rows = 3:4)
			  )
```

### Output Format

```{r modelOut, eval = FALSE}
msummary(models, filename = 'table.tex')
msummary(models, filename = 'table.rtf')
msummary(models, filename = 'table.html')
msummary(models, filename = 'table.jpeg')
msummary(models, filename = 'table.png')
```


## Take-Home Points

1. R is power on visualization.
1. Pretty &prop; complexity.
1. The fancier is unnecessarily the better.

## Thank you!

<i class="fa fa-envelope fa-lg"></i>&nbsp; [yuehu@tsinghua.edu.cn](mailto:yuehu@tsinghua.edu.cn)

<i class="fa fa-globe fa-lg"></i>&nbsp; https://sammo3182.github.io/

<i class="fab fa-github fa-lg"></i>&nbsp; [sammo3182](https://github.com/sammo3182)