the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung...
Transcript of the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung...
![Page 1: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/1.jpg)
CC by RStudio
the Tidyverse and
ggplot2
Sungkyu Jung
excepted from slides at Rstudio.com (00-Tidyverse-webinar)
![Page 2: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/2.jpg)
R Packages
![Page 3: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/3.jpg)
function1()function2()function3()function4()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function5()function6()function7()function8()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function9()functionA()functionB()functionC()
help help help
p p p p10071007100710071009100910091009p p p
p p p
functionD()functionE()functionF()functionG()
help help help
p p p p10071007100710071009100910091009p p p
p p p
![Page 4: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/4.jpg)
function1()function2()function3()function4()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function5()function6()function7()function8()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function9()functionA()functionB()functionC()
help help help
p p p p10071007100710071009100910091009p p p
p p p
functionD()functionE()functionF()functionG()
help help help
p p p p10071007100710071009100910091009p p p
p p p
Base R
![Page 5: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/5.jpg)
function1()function2()function3()function4()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function5()function6()function7()function8()
help help help
p p p p10071007100710071009100910091009p p p
p p p
function9()functionA()functionB()functionC()
help help help
p p p p10071007100710071009100910091009p p p
p p p
functionD()functionE()functionF()functionG()
help help help
p p p p10071007100710071009100910091009p p p
p p p
Base R R Packages
![Page 6: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/6.jpg)
CC by RStudio
Using packages
install.packages("foo")
Downloads files to computer
1
1 x per computer
![Page 7: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/7.jpg)
CC by RStudio
Using packages
install.packages("foo")
Downloads files to computer
1library("foo")
Loads package
2
1 x per computer 1 x per R Session
![Page 8: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/8.jpg)
CC by RStudioDisplay by Adolfo A ́lvarez
The TidyverseA collection of modern R packages that share common philosophies, embed best practices, and are designed to work together.
CC by RStudio
![Page 9: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/9.jpg)
CC by RStudio
tidyverseAn R package that serves as a short cut for installing and loading the components of the tidyverse.
library("tidyverse")
![Page 10: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/10.jpg)
CC by RStudio
install.packages("tidyverse")
does the equivalent ofinstall.packages("ggplot2")install.packages("dplyr")install.packages("tidyr")install.packages("readr")install.packages("purrr")install.packages("tibble")install.packages("hms")install.packages("stringr")install.packages("lubridate")install.packages("forcats")install.packages("DBI")install.packages("haven")install.packages("httr")install.packages("jsonlite")install.packages("readxl")install.packages("rvest")install.packages("xml2")install.packages("modelr")install.packages("broom")
![Page 11: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/11.jpg)
CC by RStudio
install.packages("tidyverse")
does the equivalent ofinstall.packages("ggplot2")install.packages("dplyr")install.packages("tidyr")install.packages("readr")install.packages("purrr")install.packages("tibble")install.packages("hms")install.packages("stringr")install.packages("lubridate")install.packages("forcats")install.packages("DBI")install.packages("haven")install.packages("httr")install.packages("jsonlite")install.packages("readxl")install.packages("rvest")install.packages("xml2")install.packages("modelr")install.packages("broom")
library("tidyverse")
does the equivalent oflibrary("ggplot2")library("dplyr")library("tidyr")library("readr")library("purrr")library("tibble")
![Page 12: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/12.jpg)
CC by RStudio
install.packages("tidyverse")
does the equivalent ofinstall.packages("ggplot2")install.packages("dplyr")install.packages("tidyr")install.packages("readr")install.packages("purrr")install.packages("tibble")install.packages("hms")install.packages("stringr")install.packages("lubridate")install.packages("forcats")install.packages("DBI")install.packages("haven")install.packages("httr")install.packages("jsonlite")install.packages("readxl")install.packages("rvest")install.packages("xml2")install.packages("modelr")install.packages("broom")
library("tidyverse")
does the equivalent oflibrary("ggplot2")library("dplyr")library("tidyr")library("readr")library("purrr")library("tibble")
Six functions • arrange() • filter() • select() • mutate() • summarise() • group_by()
Visualization tools
![Page 13: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/13.jpg)
Grammar of Graphics
![Page 14: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/14.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
data geom
![Page 15: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/15.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
data geom
mappingsfill
![Page 16: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/16.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
fillshape
data geom
mappings
![Page 17: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/17.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
shape fillx
data geom
mappings
![Page 18: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/18.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
y xshape fill
data geom
mappings
![Page 19: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/19.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
xshape filly
pointslines
data geom
mappings
![Page 20: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/20.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
xy
linesbars
pointsdata geom
mappings
![Page 21: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/21.jpg)
CC by RStudio
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
mappingsy
geomdata
linesbars
points
xfill
![Page 22: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/22.jpg)
To make a graph
CC by RStudio
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))[template]
![Page 23: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/23.jpg)
To make a graph
dataCC by RStudio
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
1. Pick a data setmpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
![Page 24: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/24.jpg)
To make a graph
CC by RStudio
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
1. Pick a data set
2. Choose a geom to display cases
mpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
data geom
![Page 25: the Tidyverse and ggplot2 - Statistics€¦ · CC by RStudio the Tidyverse and ggplot2 Sungkyu Jung excepted from slides at Rstudio.com (00-Tidyverse-webinar)](https://reader033.fdocuments.net/reader033/viewer/2022052320/5f154f1263fb1f6e816e0be0/html5/thumbnails/25.jpg)
To make a graphmpg cyl disp hp
21.0 6 160.0 221.0 6 160.0 222.8 4 108.0 121.4 6 258.0 218.7 8 360.0 318.1 6 225.0 214.3 8 360.0 524.4 4 146.7 122.8 4 140.8 119.2 6 167.6 217.8 6 167.6 216.4 8 275.8 317.3 8 275.8 315.2 8 275.8 310.4 8 472.0 410.4 8 460.0 414.7 8 440.0 432.4 4 78.7 130.4 4 75.7 133.9 4 71.1 1
data geom
mappingsfill
CC by RStudio
ggplot(data = <DATA>) + <GEOM_FUNCTION>(mapping = aes(<MAPPINGS>))
1. Pick a data set
2. Choose a geom to display cases
3. Map aesthetic properties to variables