ML Home | MLR Book Home

library(tidyverse)

Plot Iris

library(ggplot2)
data(iris)
myPlot <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  geom_point() +
  theme_bw()

myPlot

Iris: ggplot shape = Species

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, shape = Species)) +
  geom_point()  +
  theme_bw()

Iris: ggplot col = Species

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width, col = Species)) +
  geom_point()  +
  theme_bw()

Iris facet_wrap

ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  facet_wrap(~ Species) +
  geom_point()  +
  theme_bw()

We use this data for various maps.

listOfNumerics <- list(a = rnorm(5),
                       b = rnorm(9),
                       c = rnorm(10))

listOfNumerics
## $a
## [1]  0.0826785  0.7690771 -0.5622437 -0.4805259  0.3639989
## 
## $b
## [1] -1.2680962  2.5861386  0.8318649 -0.8834166  0.1528102  0.3895827  1.5991114
## [8] -1.5752840 -2.7172683
## 
## $c
##  [1]  0.4837824 -0.4719966 -0.1895478 -1.0276589  1.3135611 -0.4475964
##  [7] -0.6413699  1.0267952  1.6636854 -0.6143755

map

map_int

map_df

map with lambdas

map2

iterate simultaneously over multiple lists

multipliers <- list(0.5, 10, 3)

map2(.x = listOfNumerics, .y = multipliers, ~.x * .y)
## $a
## [1]  0.04133925  0.38453857 -0.28112185 -0.24026294  0.18199946
## 
## $b
## [1] -12.680962  25.861386   8.318649  -8.834166   1.528102   3.895827  15.991114
## [8] -15.752840 -27.172683
## 
## $c
##  [1]  1.4513471 -1.4159898 -0.5686433 -3.0829766  3.9406832 -1.3427891
##  [7] -1.9241096  3.0803856  4.9910563 -1.8431264

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

walk and iwalk

pmap

Iterate over each column of a dataframe.