August 26, 2019

Lets continue with , Explore and Visualize

This week we will finish reading Chapter 3 and discuss Chapter 4.

Faceting

From the authors.

"… particularly useful for categorical variables, is to split your plot into facets, subplots that each display one subset of the data."

Geometric shapes

How to add a smoothing line to a scatterplot?

ggplot(data = mpg) +

geom_point(mapping = aes(x = displ, y = hwy))

ggplot(data = mpg) +

geom_smooth(mapping = aes(x = displ, y = hwy))

left plot

library(tidyverse)
ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy))

right plot

ggplot(data = mpg) + 
  geom_smooth(mapping = aes(x = displ, y = hwy))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

together

ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy)) + 
  geom_smooth(mapping = aes(x = displ, y = hwy))
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Multiple smoothing lines

## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

Statistical transformations

Proportions

Position adjustment

"identity", "dodge" or "fill"