class: center, middle, inverse, title-slide # The Tidyverse for Archaeologists ## A Guide for Beginners ### Ben Marwick, November 2020 --- class: center, left .pull-left[ <img class="mask" /> ] .pull-right[ # Find me at... .left[ [<svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M459.37 151.716c.325 4.548.325 9.097.325 13.645 0 138.72-105.583 298.558-298.558 298.558-59.452 0-114.68-17.219-161.137-47.106 8.447.974 16.568 1.299 25.34 1.299 49.055 0 94.213-16.568 130.274-44.832-46.132-.975-84.792-31.188-98.112-72.772 6.498.974 12.995 1.624 19.818 1.624 9.421 0 18.843-1.3 27.614-3.573-48.081-9.747-84.143-51.98-84.143-102.985v-1.299c13.969 7.797 30.214 12.67 47.431 13.319-28.264-18.843-46.781-51.005-46.781-87.391 0-19.492 5.197-37.36 14.294-52.954 51.655 63.675 129.3 105.258 216.365 109.807-1.624-7.797-2.599-15.918-2.599-24.04 0-57.828 46.782-104.934 104.934-104.934 30.213 0 57.502 12.67 76.67 33.137 23.715-4.548 46.456-13.32 66.599-25.34-7.798 24.366-24.366 44.833-46.132 57.827 21.117-2.273 41.584-8.122 60.426-16.243-14.292 20.791-32.161 39.308-52.628 54.253z"/></svg> @benmarwick](http://twitter.com/benmarwick) [<svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 496 512"><path d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"/></svg> @benmarwick](http://github.com/benmarwick) [<svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M326.612 185.391c59.747 59.809 58.927 155.698.36 214.59-.11.12-.24.25-.36.37l-67.2 67.2c-59.27 59.27-155.699 59.262-214.96 0-59.27-59.26-59.27-155.7 0-214.96l37.106-37.106c9.84-9.84 26.786-3.3 27.294 10.606.648 17.722 3.826 35.527 9.69 52.721 1.986 5.822.567 12.262-3.783 16.612l-13.087 13.087c-28.026 28.026-28.905 73.66-1.155 101.96 28.024 28.579 74.086 28.749 102.325.51l67.2-67.19c28.191-28.191 28.073-73.757 0-101.83-3.701-3.694-7.429-6.564-10.341-8.569a16.037 16.037 0 0 1-6.947-12.606c-.396-10.567 3.348-21.456 11.698-29.806l21.054-21.055c5.521-5.521 14.182-6.199 20.584-1.731a152.482 152.482 0 0 1 20.522 17.197zM467.547 44.449c-59.261-59.262-155.69-59.27-214.96 0l-67.2 67.2c-.12.12-.25.25-.36.37-58.566 58.892-59.387 154.781.36 214.59a152.454 152.454 0 0 0 20.521 17.196c6.402 4.468 15.064 3.789 20.584-1.731l21.054-21.055c8.35-8.35 12.094-19.239 11.698-29.806a16.037 16.037 0 0 0-6.947-12.606c-2.912-2.005-6.64-4.875-10.341-8.569-28.073-28.073-28.191-73.639 0-101.83l67.2-67.19c28.239-28.239 74.3-28.069 102.325.51 27.75 28.3 26.872 73.934-1.155 101.96l-13.087 13.087c-4.35 4.35-5.769 10.79-3.783 16.612 5.864 17.194 9.042 34.999 9.69 52.721.509 13.906 17.454 20.446 27.294 10.606l37.106-37.106c59.271-59.259 59.271-155.699.001-214.959z"/></svg> faculty.washington.edu/bmarwick](http://faculty.washington.edu/bmarwick) [<svg style="height:0.8em;top:.04em;position:relative;" viewBox="0 0 512 512"><path d="M476 3.2L12.5 270.6c-18.1 10.4-15.8 35.6 2.2 43.2L121 358.4l287.3-253.2c5.5-4.9 13.3 2.6 8.6 8.3L176 407v80.5c0 23.6 28.5 32.9 42.5 15.8L282 426l124.6 52.2c14.2 6 30.4-2.9 33-18.2l72-432C515 7.8 493.3-6.8 476 3.2z"/></svg> bmarwick@uw.edu](mailto:bmarwick@uw.edu) ] ] --- # Welcome - The **[tidyverse](https://www.tidyverse.org/)** is an opinionated collection of R packages designed for data science. They are efficient to learn because they share an underlying design philosophy, grammar, and data structures. -- - Many common tasks of archaeological data analysis can be done **easily** with the tidyverse. -- - When we write R code to analyse archaeological data, our analysis is **transparent and reproducible**. These are two vital characteristics of good scientific work. -- - We should [**share our code and data**](https://github.com/benmarwick/ctv-archaeology/blob/master/README.md) with our research publications for others to study and learn --- # What are we going to do today? I will demonstrate and you will practice... -- - Importing and inspecting archaeological data -- - Five main verbs of the dplyr package to analyse data -- - Five main plots of the ggplot2 package to visualise data --- class: center, middle # Let's import some archaeological data 💽 --- class: left, middle background-image: url(figures/data-source-paper.png) background-size: contain --- class: split-40 count: false .left-code-import-auto[ ```r *library(rio) ``` ] .right-output-import-auto[ ] --- class: split-40 count: false .left-code-import-auto[ ```r library(rio) # read in the data *j_data <- import("https://bit.ly/j_data_xlsx", setclass = "tbl_df") ``` ] .right-output-import-auto[ ] --- class: split-40 count: false .left-code-import-auto[ ```r library(rio) # read in the data j_data <- import("https://bit.ly/j_data_xlsx", setclass = "tbl_df") # take a look *j_data ``` ] .right-output-import-auto[ ``` # A tibble: 9,752 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 37 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ] <style> .left-code-import-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-import-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: left, middle background-image: url(https://images.unsplash.com/photo-1515490480959-ce9152f7ea2b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2850&q=80) background-size: cover --- # Your turn ```r library(rio) # read in the data j_data <- import("https://bit.ly/j_data_xlsx", setclass = "tbl_df") # take a look j_data ```
05
:
00
--- class: center, middle # Let's inspect our archaeological data 🔎 --- class: split-40 count: false .left-code-inspect1-auto[ ```r # check the class *class(j_data) ``` ] .right-output-inspect1-auto[ ``` [1] "tbl_df" "tbl" "data.frame" ``` ] --- class: split-40 count: false .left-code-inspect1-auto[ ```r # check the class class(j_data) # check the size: rows *nrow(j_data) ``` ] .right-output-inspect1-auto[ ``` [1] "tbl_df" "tbl" "data.frame" ``` ``` [1] 9752 ``` ] --- class: split-40 count: false .left-code-inspect1-auto[ ```r # check the class class(j_data) # check the size: rows nrow(j_data) # check the size: columns *ncol(j_data) ``` ] .right-output-inspect1-auto[ ``` [1] "tbl_df" "tbl" "data.frame" ``` ``` [1] 9752 ``` ``` [1] 48 ``` ] --- class: split-40 count: false .left-code-inspect1-auto[ ```r # check the class class(j_data) # check the size: rows nrow(j_data) # check the size: columns ncol(j_data) # check the column names *names(j_data) ``` ] .right-output-inspect1-auto[ ``` [1] "tbl_df" "tbl" "data.frame" ``` ``` [1] 9752 ``` ``` [1] 48 ``` ``` [1] "Site" "Square" "Spit" "Group" "Artno" [6] "Material" "Colour" "Weight" "Length" "Artclas" [11] "Cortex" "Cortype" "Initiat" "Breaks" "Noseg" [16] "Platwid" "Plat" "Focal" "Overhang" "NoDS" [21] "NoPS" "Rtch" "Plat_2" "Focal_2" "Overhang_2" [26] "NoDS_2" "NoPS_2" "Rtch_2" "RetOri" "Retype" [31] "Retloc" "Retlen" "Retdep" "Portion" "Heat" [36] "EdgeDam" "Weathering" "Corerot" "RetScNo" "Term" [41] "Janus" "Recycled" "Redirect" "Width" "Thick" [46] "Platthic" "area" "elongation" ``` ] <style> .left-code-inspect1-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-inspect1-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-inspect2-auto[ ```r # check the first few rows *head(j_data) ``` ] .right-output-inspect2-auto[ ``` # A tibble: 6 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA # … with 37 more variables: Cortype <chr>, Initiat <chr>, Breaks <chr>, # Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, Overhang <chr>, # NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, Focal_2 <lgl>, # Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, RetOri <chr>, # Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, Portion <chr>, # Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, RetScNo <dbl>, # Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, Width <dbl>, # Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ] --- class: split-40 count: false .left-code-inspect2-auto[ ```r # check the first few rows head(j_data) # check the structure *str(j_data) ``` ] .right-output-inspect2-auto[ ``` # A tibble: 6 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA # … with 37 more variables: Cortype <chr>, Initiat <chr>, Breaks <chr>, # Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, Overhang <chr>, # NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, Focal_2 <lgl>, # Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, RetOri <chr>, # Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, Portion <chr>, # Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, RetScNo <dbl>, # Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, Width <dbl>, # Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ``` tibble [9,752 × 48] (S3: tbl_df/tbl/data.frame) $ Site : chr [1:9752] "J" "J" "J" "J" ... $ Square : chr [1:9752] "B" "B" "B" "B" ... $ Spit : num [1:9752] 1 1 1 1 1 1 1 1 1 1 ... $ Group : num [1:9752] 1 1 1 1 1 1 1 1 1 1 ... $ Artno : num [1:9752] 1 2 3 4 5 6 7 8 9 10 ... $ Material : chr [1:9752] "Chert" "Chert" "Chert" "Chert" ... $ Colour : chr [1:9752] "Brown" "Yellow" "Dk Grey" "Grey" ... $ Weight : num [1:9752] 1.83 0.61 3.81 0.13 0.05 0.58 0.03 0.02 0.21 0.25 ... $ Length : num [1:9752] 22.03 14.59 29.59 5.83 7.07 ... $ Artclas : chr [1:9752] "Flake" "RetF" "Core" "RetFrag" ... $ Cortex : num [1:9752] 0 0 0 0 0 NA 0 0 0 0 ... $ Cortype : chr [1:9752] NA NA NA NA ... $ Initiat : chr [1:9752] "Hertz" "Hertz" NA NA ... $ Breaks : chr [1:9752] NA NA NA "Both" ... $ Noseg : num [1:9752] NA 3 NA 1 NA NA NA NA NA NA ... $ Platwid : num [1:9752] 20.31 10.97 NA NA 6.05 ... $ Plat : chr [1:9752] "2-scars" "3-scars" NA NA ... $ Focal : logi [1:9752] NA NA NA NA NA NA ... $ Overhang : chr [1:9752] "Yes" "Yes" NA NA ... $ NoDS : num [1:9752] 5 5 10 2 3 11 3 1 3 5 ... $ NoPS : num [1:9752] 2 3 NA NA 2 NA 1 NA NA 1 ... $ Rtch : chr [1:9752] NA "Yes" NA "Yes" ... $ Plat_2 : chr [1:9752] "2-scars" "3-scars" NA NA ... $ Focal_2 : logi [1:9752] NA NA NA NA NA NA ... $ Overhang_2: chr [1:9752] "Yes" "Yes" NA NA ... $ NoDS_2 : num [1:9752] 5 5 10 2 3 11 3 1 3 5 ... $ NoPS_2 : num [1:9752] 2 3 NA NA 2 NA 1 NA NA 1 ... $ Rtch_2 : chr [1:9752] NA "Yes" NA "Yes" ... $ RetOri : chr [1:9752] NA "Both" NA "V-D" ... $ Retype : chr [1:9752] NA "Percus" NA "Press" ... $ Retloc : chr [1:9752] NA "Rlat" NA "Dist" ... $ Retlen : num [1:9752] NA 10.75 NA 2.05 NA ... $ Retdep : num [1:9752] NA 3.04 NA 2.04 NA NA NA NA NA NA ... $ Portion : chr [1:9752] NA NA NA "Dist" ... $ Heat : num [1:9752] NA NA 1 NA NA NA NA NA NA NA ... $ EdgeDam : num [1:9752] NA NA NA NA 1 NA NA NA NA NA ... $ Weathering: num [1:9752] NA NA 1 NA NA NA NA NA NA NA ... $ Corerot : num [1:9752] NA NA 4 NA NA 4 NA NA NA NA ... $ RetScNo : num [1:9752] NA 3 NA 1 NA NA NA NA NA NA ... $ Term : chr [1:9752] "Feather" "Feather" NA "Retouched" ... $ Janus : logi [1:9752] NA NA NA NA NA NA ... $ Recycled : logi [1:9752] NA NA NA NA NA NA ... $ Redirect : logi [1:9752] NA NA NA NA NA NA ... $ Width : num [1:9752] 20.37 19.11 11.58 6.54 6.56 ... $ Thick : num [1:9752] 3.34 2.74 7.25 2.05 1.13 4.79 1.16 1.09 3.91 3.13 ... $ Platthic : num [1:9752] 2 1.62 NA NA 1.63 NA 0.69 NA NA 2.01 ... $ area : num [1:9752] 448.8 278.8 342.7 38.1 46.4 ... $ elongation: num [1:9752] 1.081 0.763 2.555 0.891 1.078 ... ``` ] <style> .left-code-inspect2-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-inspect2-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: left, middle background-image: url(https://images.unsplash.com/photo-1494129935429-873eafa78178?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2878&q=80) background-size: cover --- background-image: url(https://images.unsplash.com/photo-1507652955-f3dcef5a3be5?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80) background-size: cover # Your turn --- # Your turn ```r # check the class class(j_data) # check the size: rows nrow(j_data) # check the size: columns ncol(j_data) # check the column names names(j_data) ``` ```r # check the first few rows head(j_data) # check the structure str(j_data) ```
05
:
00
--- class: center, middle # Let's analyse our archaeological data with the dplyr & ggplot2 pkgs 🛠️ Just for fun, we will do one main dplyr verb followed by one main type of ggplot. But you can combine and mix up the verbs and plots however you want to. Verb | Plot ------------- | ------------- **select** 🔜 | **histogram** 🔜 --- background-image: url(https://images.unsplash.com/photo-1540660290370-8aa90e451e8a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80) background-size: cover --- class: split-40 count: false .left-code-dplyr1-auto[ ```r *library(tidyverse) ``` ] .right-output-dplyr1-auto[ ] --- class: split-40 count: false .left-code-dplyr1-auto[ ```r library(tidyverse) # `select` helps us # choose columns *j_data # say 'then' ``` ] .right-output-dplyr1-auto[ ``` # A tibble: 9,752 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 37 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr1-auto[ ```r library(tidyverse) # `select` helps us # choose columns j_data %>% # say 'then' * select(Square, * Spit, * Weight) ``` ] .right-output-dplyr1-auto[ ``` # A tibble: 9,752 x 3 Square Spit Weight <chr> <dbl> <dbl> 1 B 1 1.83 2 B 1 0.61 3 B 1 3.81 4 B 1 0.13 5 B 1 0.05 6 B 1 0.580 7 B 1 0.03 8 B 1 0.02 9 B 1 0.21 10 B 1 0.25 # … with 9,742 more rows ``` ] --- class: split-40 count: false .left-code-dplyr1-auto[ ```r library(tidyverse) # `select` helps us # choose columns j_data %>% # say 'then' select(Square, Spit, Weight) # `select` can use # rules to save time *j_data # say 'then' ``` ] .right-output-dplyr1-auto[ ``` # A tibble: 9,752 x 3 Square Spit Weight <chr> <dbl> <dbl> 1 B 1 1.83 2 B 1 0.61 3 B 1 3.81 4 B 1 0.13 5 B 1 0.05 6 B 1 0.580 7 B 1 0.03 8 B 1 0.02 9 B 1 0.21 10 B 1 0.25 # … with 9,742 more rows ``` ``` # A tibble: 9,752 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 37 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr1-auto[ ```r library(tidyverse) # `select` helps us # choose columns j_data %>% # say 'then' select(Square, Spit, Weight) # `select` can use # rules to save time j_data %>% # say 'then' * select_if(is.numeric) ``` ] .right-output-dplyr1-auto[ ``` # A tibble: 9,752 x 3 Square Spit Weight <chr> <dbl> <dbl> 1 B 1 1.83 2 B 1 0.61 3 B 1 3.81 4 B 1 0.13 5 B 1 0.05 6 B 1 0.580 7 B 1 0.03 8 B 1 0.02 9 B 1 0.21 10 B 1 0.25 # … with 9,742 more rows ``` ``` # A tibble: 9,752 x 24 Spit Group Artno Weight Length Cortex Noseg Platwid NoDS NoPS NoDS_2 <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> 1 1 1 1 1.83 22.0 0 NA 20.3 5 2 5 2 1 1 2 0.61 14.6 0 3 11.0 5 3 5 3 1 1 3 3.81 29.6 0 NA NA 10 NA 10 4 1 1 4 0.13 5.83 0 1 NA 2 NA 2 5 1 1 5 0.05 7.07 0 NA 6.05 3 2 3 6 1 1 6 0.580 11.1 NA NA NA 11 NA 11 7 1 1 7 0.03 5.72 0 NA 2.91 3 1 3 8 1 1 8 0.02 8.37 0 NA NA 1 NA 1 9 1 1 9 0.21 10.7 0 NA NA 3 NA 3 10 1 1 10 0.25 14.3 0 NA 3.78 5 1 5 # … with 9,742 more rows, and 13 more variables: NoPS_2 <dbl>, Retlen <dbl>, # Retdep <dbl>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, # elongation <dbl> ``` ] <style> .left-code-dplyr1-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-dplyr1-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: left, middle background-image: url(https://images.unsplash.com/photo-1565936795196-4f283b0ae59b?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=992&q=80) background-size: cover --- background-image: url(https://images.unsplash.com/photo-1553250135-606ca563bcb3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2081&q=80) background-size: cover # Your turn ---
05
:
00
# Your turn ```r library(tidyverse) # `select` helps us # choose columns j_data %>% # say 'then' select(Square, Spit, Weight) # `select` can use # rules to save time j_data %>% # say 'then' select_if(is.numeric) ``` --- class: center, middle # Let's make a histogram <img src="figures/noun_histogram_2312161.png" style="display: inline-block; margin: 0" width="50px" height="50px" /> --- class: split-40 count: false .left-code-ggplot1a-auto[ ```r # we create a new # data frame for # plotting *j_data1 <- j_data ``` ] .right-output-ggplot1a-auto[ ] --- class: split-40 count: false .left-code-ggplot1a-auto[ ```r # we create a new # data frame for # plotting j_data1 <- j_data %>% * select(Square, * Spit, * Material, * Weight, * Thick) ``` ] .right-output-ggplot1a-auto[ ] --- class: split-40 count: false .left-code-ggplot1a-auto[ ```r # we create a new # data frame for # plotting j_data1 <- j_data %>% select(Square, Spit, Material, Weight, Thick) # take a look *j_data1 ``` ] .right-output-ggplot1a-auto[ ``` # A tibble: 9,752 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 B 1 Chert 1.83 3.34 2 B 1 Chert 0.61 2.74 3 B 1 Chert 3.81 7.25 4 B 1 Chert 0.13 2.05 5 B 1 Chert 0.05 1.13 6 B 1 Chert 0.580 4.79 7 B 1 Chert 0.03 1.16 8 B 1 Chert 0.02 1.09 9 B 1 Chert 0.21 3.91 10 B 1 Chert 0.25 3.13 # … with 9,742 more rows ``` ] <style> .left-code-ggplot1a-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1a-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot1b-auto[ ```r *ggplot(data = j_data1) ``` ] .right-output-ggplot1b-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1b_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1b-auto[ ```r ggplot(data = j_data1) + * aes(x = Weight) ``` ] .right-output-ggplot1b-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1b_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1b-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + * geom_histogram() ``` ] .right-output-ggplot1b-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1b_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1b-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() ``` ] .right-output-ggplot1b-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1b_auto_4_output-1.png" width="432" /> ] <style> .left-code-ggplot1b-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1b-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot1c-user[ ```r *ggplot(data = j_data1) + * aes(x = Weight) + * geom_histogram() ``` ] .right-output-ggplot1c-user[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1c_user_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1c-user[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + * scale_x_log10() ``` ] .right-output-ggplot1c-user[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1c_user_2_output-1.png" width="432" /> ] <style> .left-code-ggplot1c-user { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1c-user { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot1d-rotate[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10() + NULL ``` ] .right-output-ggplot1d-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1d_rotate_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1d-rotate[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + * scale_x_log10(labels = scales::comma) + NULL ``` ] .right-output-ggplot1d-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1d_rotate_2_output-1.png" width="432" /> ] <style> .left-code-ggplot1d-rotate { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1d-rotate { width: 35%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r *ggplot(data = j_data1) ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r ggplot(data = j_data1) + * aes(x = Weight) ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + * geom_histogram() ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + * scale_x_log10(labels = scales::comma) ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10(labels = scales::comma) + * theme_minimal() ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1e-auto[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10(labels = scales::comma) + theme_minimal() ``` ] .right-output-ggplot1e-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1e_auto_6_output-1.png" width="432" /> ] <style> .left-code-ggplot1e-auto { color: #777; width: 38%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1e-auto { width: 60%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot1f-rotate[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10(labels = scales::comma) + theme_minimal() + NULL ``` ] .right-output-ggplot1f-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1f_rotate_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot1f-rotate[ ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10(labels = scales::comma) + * theme_minimal(base_size = 20) + NULL ``` ] .right-output-ggplot1f-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot1f_rotate_2_output-1.png" width="432" /> ] <style> .left-code-ggplot1f-rotate { color: #777; width: 50%; height: 92%; float: left; font-size: 80% } .right-output-ggplot1f-rotate { width: 45%; float: right; padding-left: 1%; } </style> --- background-image: url(https://images.unsplash.com/photo-1567602612078-2f1504cbe535?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1567&q=80) background-size: cover # Your turn --- background-image: url(https://images.unsplash.com/photo-1484100356142-db6ab6244067?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1562&q=80) background-size: cover # Your turn --- # Your turn ```r j_data1 <- j_data %>% select(Square, Spit, Material, Weight, Thick) ``` ```r ggplot(data = j_data1) + aes(x = Weight) + geom_histogram() + scale_x_log10(labels = scales::comma) + theme_minimal(base_size = 20) ```
05
:
00
--- class: center, middle # What have we done? Verb | Plot ------------- | ------------- select ✅ | histogram ✅ **filter** 🔜 | **scatterplot** 🔜 --- class: split-40 count: false .left-code-dplyr2-auto[ ```r # `filter` helps us # choose rows *j_data1 ``` ] .right-output-dplyr2-auto[ ``` # A tibble: 9,752 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 B 1 Chert 1.83 3.34 2 B 1 Chert 0.61 2.74 3 B 1 Chert 3.81 7.25 4 B 1 Chert 0.13 2.05 5 B 1 Chert 0.05 1.13 6 B 1 Chert 0.580 4.79 7 B 1 Chert 0.03 1.16 8 B 1 Chert 0.02 1.09 9 B 1 Chert 0.21 3.91 10 B 1 Chert 0.25 3.13 # … with 9,742 more rows ``` ] --- class: split-40 count: false .left-code-dplyr2-auto[ ```r # `filter` helps us # choose rows j_data1 %>% # is equivalent to... * filter(Square == "A") ``` ] .right-output-dplyr2-auto[ ``` # A tibble: 4,436 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 A 1 Chert 1.74 4.37 2 A 1 Chert 1.64 4.09 3 A 1 Obsidian 0.12 1.41 4 A 1 Chert 2.12 5.96 5 A 1 Chert 2.25 7.62 6 A 1 Chert 4.88 8.97 7 A 1 Chert 8.95 16.0 8 A 1 Chert 3.02 8.15 9 A 1 Chert 2.71 6.44 10 A 1 Chert 1.31 5.84 # … with 4,426 more rows ``` ] --- class: split-40 count: false .left-code-dplyr2-auto[ ```r # `filter` helps us # choose rows j_data1 %>% # is equivalent to... filter(Square == "A") %>% # is less than... * filter(Weight < 10) ``` ] .right-output-dplyr2-auto[ ``` # A tibble: 4,416 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 A 1 Chert 1.74 4.37 2 A 1 Chert 1.64 4.09 3 A 1 Obsidian 0.12 1.41 4 A 1 Chert 2.12 5.96 5 A 1 Chert 2.25 7.62 6 A 1 Chert 4.88 8.97 7 A 1 Chert 8.95 16.0 8 A 1 Chert 3.02 8.15 9 A 1 Chert 2.71 6.44 10 A 1 Chert 1.31 5.84 # … with 4,406 more rows ``` ] --- class: split-40 count: false .left-code-dplyr2-auto[ ```r # `filter` helps us # choose rows j_data1 %>% # is equivalent to... filter(Square == "A") %>% # is less than... filter(Weight < 10) %>% # is between x and y * filter(between(Thick, 0.2, 20)) ``` ] .right-output-dplyr2-auto[ ``` # A tibble: 4,392 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 A 1 Chert 1.74 4.37 2 A 1 Chert 1.64 4.09 3 A 1 Obsidian 0.12 1.41 4 A 1 Chert 2.12 5.96 5 A 1 Chert 2.25 7.62 6 A 1 Chert 4.88 8.97 7 A 1 Chert 8.95 16.0 8 A 1 Chert 3.02 8.15 9 A 1 Chert 2.71 6.44 10 A 1 Chert 1.31 5.84 # … with 4,382 more rows ``` ] --- class: split-40 count: false .left-code-dplyr2-auto[ ```r # `filter` helps us # choose rows j_data1 %>% # is equivalent to... filter(Square == "A") %>% # is less than... filter(Weight < 10) %>% # is between x and y filter(between(Thick, 0.2, 20)) %>% # is not NA * filter(!is.na(Material)) ``` ] .right-output-dplyr2-auto[ ``` # A tibble: 4,392 x 5 Square Spit Material Weight Thick <chr> <dbl> <chr> <dbl> <dbl> 1 A 1 Chert 1.74 4.37 2 A 1 Chert 1.64 4.09 3 A 1 Obsidian 0.12 1.41 4 A 1 Chert 2.12 5.96 5 A 1 Chert 2.25 7.62 6 A 1 Chert 4.88 8.97 7 A 1 Chert 8.95 16.0 8 A 1 Chert 3.02 8.15 9 A 1 Chert 2.71 6.44 10 A 1 Chert 1.31 5.84 # … with 4,382 more rows ``` ] <style> .left-code-dplyr2-auto { color: #777; width: 50%; height: 92%; float: left; font-size: 80% } .right-output-dplyr2-auto { width: 45%; float: right; padding-left: 1%; } </style> --- class: center, middle # Let's make a scatterplot <img src="figures/noun_Scatter Plot_105485.png" style="display: inline-block; margin: 0" width="50px" height="50px" /> --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r *ggplot(data = j_data2) ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + * aes(x = Weight, * y = Thick) ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + * geom_point() ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + geom_point() + * scale_x_log10() ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + geom_point() + scale_x_log10() + * scale_y_log10() ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + geom_point() + scale_x_log10() + scale_y_log10() + * theme_bw(base_size = 30) ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_6_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2a-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + geom_point() + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 30) + * labs(x = "Mass (g)", * y = "Thickness (mm)") ``` ] .right-output-ggplot2a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2a_auto_7_output-1.png" width="432" /> ] <style> .left-code-ggplot2a-auto { color: #777; width: 45%; height: 92%; float: left; font-size: 80% } .right-output-ggplot2a-auto { width: 50%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot2b-rotate[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + geom_point() + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 30) + labs(x = "Mass (g)", y = "Thickness (mm)") ``` ] .right-output-ggplot2b-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2b_rotate_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2b-rotate[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + * geom_point(size = 4) + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 30) + labs(x = "Mass (g)", y = "Thickness (mm)") ``` ] .right-output-ggplot2b-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2b_rotate_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2b-rotate[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick) + * geom_point(size = 4, alpha = 0.1) + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 30) + labs(x = "Mass (g)", y = "Thickness (mm)") ``` ] .right-output-ggplot2b-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2b_rotate_3_output-1.png" width="432" /> ] <style> .left-code-ggplot2b-rotate { color: #777; width: 55%; height: 92%; float: left; font-size: 80% } .right-output-ggplot2b-rotate { width: 40%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r *ggplot(data = j_data2) ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + * aes(x = Weight, * y = Thick, * colour = Material) ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + * geom_point(size = 4) ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + * scale_x_log10() ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + scale_x_log10() + * scale_y_log10() ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + scale_x_log10() + scale_y_log10() + * theme_bw(base_size = 10) ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_6_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 10) + * labs(x = "Mass (g)", * y = "Thickness (mm)") ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_7_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot2c-auto[ ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 10) + labs(x = "Mass (g)", y = "Thickness (mm)") + * theme(legend.position = c(0.85, 0.3)) ``` ] .right-output-ggplot2c-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot2c_auto_8_output-1.png" width="432" /> ] <style> .left-code-ggplot2c-auto { color: #777; width: 65%; height: 92%; float: left; font-size: 80% } .right-output-ggplot2c-auto { width: 30%; float: right; padding-left: 1%; } </style> --- background-image: url(https://images.unsplash.com/photo-1572866511072-44aae0768e85?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80) background-size: cover # Your turn --- background-image: url(https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-1.2.1&auto=format&fit=crop&w=1651&q=80) background-size: cover # Your turn --- # Your turn ```r j_data2 <- j_data1 %>% filter(Square == "A") %>% filter(Weight < 10) %>% filter(between(Thick, 0.2, 20)) %>% filter(!is.na(Material)) ``` ```r ggplot(data = j_data2) + aes(x = Weight, y = Thick, colour = Material) + geom_point(size = 4) + scale_x_log10() + scale_y_log10() + theme_bw(base_size = 10) + labs(x = "Mass (g)", y = "Thickness (mm)") + theme(legend.position = c(0.85, 0.3)) ```
05
:
00
--- background-image: url(https://images.unsplash.com/photo-1524901548305-08eeddc35080?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1950&q=80) background-size: cover # Let's take a short break --- background-image: url(https://images.unsplash.com/photo-1533745848184-3db07256e163?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=2689&q=80) background-size: cover --- class: center, middle # What have we done? Verb | Plot ------------- | ------------- select ✅ | histogram ✅ filter ✅ | scatterplot ✅ **mutate** 🔜 | **boxplot** 🔜 --- class: split-40 count: false .left-code-dplyr3-auto[ ```r # `mutate` helps us # change columns *j_data ``` ] .right-output-dplyr3-auto[ ``` # A tibble: 9,752 x 48 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 37 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr3-auto[ ```r # `mutate` helps us # change columns j_data %>% # create a new column * mutate(plat_area = Platwid * Platthic) ``` ] .right-output-dplyr3-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr3-auto[ ```r # `mutate` helps us # change columns j_data %>% # create a new column mutate(plat_area = Platwid * Platthic) %>% # update an existing column * mutate(Colour = * case_when(Colour == "Dk Grey" ~ "Dark Grey", * Colour == "Lt Brown" ~ "Light Brown", * TRUE ~ Colour)) ``` ] .right-output-dplyr3-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dark … 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Light… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr3-auto[ ```r # `mutate` helps us # change columns j_data %>% # create a new column mutate(plat_area = Platwid * Platthic) %>% # update an existing column mutate(Colour = case_when(Colour == "Dk Grey" ~ "Dark Grey", Colour == "Lt Brown" ~ "Light Brown", TRUE ~ Colour)) %>% # update many columns * mutate_at(vars(Length, Width), scale) ``` ] .right-output-dplyr3-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length[,1] Artclas <chr> <chr> <dbl> <dbl> <dbl> <chr> <chr> <dbl> <dbl> <chr> 1 J B 1 1 1 Chert Brown 1.83 1.80 Flake 2 J B 1 1 2 Chert Yellow 0.61 0.629 RetF 3 J B 1 1 3 Chert Dark … 3.81 3.00 Core 4 J B 1 1 4 Chert Grey 0.13 -0.755 RetFrag 5 J B 1 1 5 Chert Grey 0.05 -0.559 Flake 6 J B 1 1 6 Chert Light… 0.580 0.0821 Core 7 J B 1 1 7 Chert Dk Br… 0.03 -0.772 Flake 8 J B 1 1 8 Chert Cream 0.02 -0.354 FFrag 9 J B 1 1 9 Chert Grey 0.21 0.0142 Flake-b 10 J B 1 1 10 Chert Grey 0.25 0.578 Flake # … with 9,742 more rows, and 39 more variables: Cortex <dbl>, Cortype <chr>, # Initiat <chr>, Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, # Focal <lgl>, Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, # Plat_2 <chr>, Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, # Rtch_2 <chr>, RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, # Retdep <dbl>, Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, # Corerot <dbl>, RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, # Redirect <lgl>, Width[,1] <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, # elongation <dbl>, plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr3-auto[ ```r # `mutate` helps us # change columns j_data %>% # create a new column mutate(plat_area = Platwid * Platthic) %>% # update an existing column mutate(Colour = case_when(Colour == "Dk Grey" ~ "Dark Grey", Colour == "Lt Brown" ~ "Light Brown", TRUE ~ Colour)) %>% # update many columns mutate_at(vars(Length, Width), scale) %>% # update an existing column * mutate(Material = fct_lump(Material, 5)) ``` ] .right-output-dplyr3-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length[,1] Artclas <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> 1 J B 1 1 1 Chert Brown 1.83 1.80 Flake 2 J B 1 1 2 Chert Yellow 0.61 0.629 RetF 3 J B 1 1 3 Chert Dark … 3.81 3.00 Core 4 J B 1 1 4 Chert Grey 0.13 -0.755 RetFrag 5 J B 1 1 5 Chert Grey 0.05 -0.559 Flake 6 J B 1 1 6 Chert Light… 0.580 0.0821 Core 7 J B 1 1 7 Chert Dk Br… 0.03 -0.772 Flake 8 J B 1 1 8 Chert Cream 0.02 -0.354 FFrag 9 J B 1 1 9 Chert Grey 0.21 0.0142 Flake-b 10 J B 1 1 10 Chert Grey 0.25 0.578 Flake # … with 9,742 more rows, and 39 more variables: Cortex <dbl>, Cortype <chr>, # Initiat <chr>, Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, # Focal <lgl>, Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, # Plat_2 <chr>, Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, # Rtch_2 <chr>, RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, # Retdep <dbl>, Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, # Corerot <dbl>, RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, # Redirect <lgl>, Width[,1] <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, # elongation <dbl>, plat_area <dbl> ``` ] <style> .left-code-dplyr3-auto { color: #777; width: 70%; height: 92%; float: left; font-size: 50% } .right-output-dplyr3-auto { width: 25%; float: right; padding-left: 1%; } </style> --- class: center, middle # Let's make a boxplot <img src="figures/noun_Box Plot_991170.png" style="display: inline-block; margin: 0" width="50px" height="50px" /> --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r *ggplot(data = j_data2) ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r ggplot(data = j_data2) + * aes(x = Material, * y = plat_area) ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r ggplot(data = j_data2) + aes(x = Material, y = plat_area) + * geom_boxplot() ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + * scale_y_log10() ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + scale_y_log10() + * labs(x = "Raw Material", * y = "Platform Area") ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3a-auto[ ```r ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + scale_y_log10() + labs(x = "Raw Material", y = "Platform Area") + * theme_classic(base_size = 12) ``` ] .right-output-ggplot3a-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3a_auto_6_output-1.png" width="432" /> ] <style> .left-code-ggplot3a-auto { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-output-ggplot3a-auto { width: 35%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot3b-non_seq[ ```r library(ggbeeswarm) ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + scale_y_log10() + labs(x = "Raw Material", y = "Platform Area") + theme_classic(base_size = 14) ``` ] .right-output-ggplot3b-non_seq[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3b_non_seq_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3b-non_seq[ ```r library(ggbeeswarm) ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + # overlay data points * geom_quasirandom(alpha = 0.1) + scale_y_log10() + labs(x = "Raw Material", y = "Platform Area") + theme_classic(base_size = 14) ``` ] .right-output-ggplot3b-non_seq[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3b_non_seq_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot3b-non_seq[ ```r library(ggbeeswarm) ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + # overlay data points geom_quasirandom(alpha = 0.1) + scale_y_log10() + labs(x = "Raw Material", y = "Platform Area") + theme_classic(base_size = 14) + * coord_flip() ``` ] .right-output-ggplot3b-non_seq[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot3b_non_seq_3_output-1.png" width="432" /> ] <style> .left-code-ggplot3b-non_seq { color: #777; width: 60%; height: 92%; float: left; font-size: 80% } .right-output-ggplot3b-non_seq { width: 35%; float: right; padding-left: 1%; } </style> --- background-image: url(https://images.unsplash.com/photo-1581941274242-25a62bdc9bf9?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80) background-size: cover # Your turn --- background-image: url(https://images.unsplash.com/photo-1586084531149-373985a4478e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=934&q=80) background-size: cover # Your turn --- # Your turn ```r j_data2 <- j_data %>% mutate(plat_area = Platwid * Platthic) %>% mutate(Material = fct_lump(Material, 5)) ``` ```r ggplot(data = j_data2) + aes(x = Material, y = plat_area) + geom_boxplot() + scale_y_log10() + labs(x = "Raw Material", y = "Platform Area") + theme_classic(base_size = 12) ```
05
:
00
--- class: center, middle # What have we done? Verb | Plot ------------- | ------------- select ✅ | histogram ✅ filter ✅ | scatterplot ✅ mutate ✅ | boxplot ✅ **group by** 🔜 | **barplot** 🔜 --- class: split-40 count: false .left-code-dplyr4-auto[ ```r *j_data2 ``` ] .right-output-dplyr4-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr4-auto[ ```r j_data2 %>% * group_by(Material) ``` ] .right-output-dplyr4-auto[ ``` # A tibble: 9,752 x 49 # Groups: Material [8] Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr4-auto[ ```r j_data2 %>% group_by(Material) %>% * tally() ``` ] .right-output-dplyr4-auto[ ``` # A tibble: 8 x 2 Material n <fct> <int> 1 Chert 9072 2 Quartz 31 3 Quartzite 50 4 Silcrete 94 5 Unknown 31 6 Volcanic 425 7 Other 39 8 <NA> 10 ``` ] --- class: split-40 count: false .left-code-dplyr4-auto[ ```r j_data2 %>% group_by(Material) %>% tally() %>% * arrange(desc(n)) ``` ] .right-output-dplyr4-auto[ ``` # A tibble: 8 x 2 Material n <fct> <int> 1 Chert 9072 2 Volcanic 425 3 Silcrete 94 4 Quartzite 50 5 Other 39 6 Quartz 31 7 Unknown 31 8 <NA> 10 ``` ] --- class: split-40 count: false .left-code-dplyr4-auto[ ```r j_data2 %>% group_by(Material) %>% tally() %>% arrange(desc(n)) ``` ] .right-output-dplyr4-auto[ ``` # A tibble: 8 x 2 Material n <fct> <int> 1 Chert 9072 2 Volcanic 425 3 Silcrete 94 4 Quartzite 50 5 Other 39 6 Quartz 31 7 Unknown 31 8 <NA> 10 ``` ] <style> .left-code-dplyr4-auto { color: #777; width: 70%; height: 92%; float: left; font-size: 50% } .right-output-dplyr4-auto { width: 25%; float: right; padding-left: 1%; } </style> --- class: center, middle # Let's make a barplot <img src="figures/noun_bar graph_1393295.png" style="display: inline-block; margin: 0" width="50px" height="50px" /> --- class: split-40 count: false .left-code-ggplot4-auto[ ```r *ggplot(data = j_data3) ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4-auto[ ```r ggplot(data = j_data3) + * aes(x = Material, * y = n) ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_2_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4-auto[ ```r ggplot(data = j_data3) + aes(x = Material, y = n) + * geom_col() ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4-auto[ ```r ggplot(data = j_data3) + aes(x = Material, y = n) + geom_col() + * scale_y_log10() ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4-auto[ ```r ggplot(data = j_data3) + aes(x = Material, y = n) + geom_col() + scale_y_log10() + * labs(x = "Raw Material", * y = "Frequency") ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4-auto[ ```r ggplot(data = j_data3) + aes(x = Material, y = n) + geom_col() + scale_y_log10() + labs(x = "Raw Material", y = "Frequency") + * theme_minimal(base_size = 14) ``` ] .right-output-ggplot4-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4_auto_6_output-1.png" width="432" /> ] <style> .left-code-ggplot4-auto { color: #777; width: 55%; height: 92%; float: left; font-size: 80% } .right-output-ggplot4-auto { width: 40%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot4a-rotate[ ```r ggplot(data = j_data3) + aes(x = Material, y = n) + geom_col() + scale_y_log10() + labs(x = "Raw Material", y = "Frequency") + theme_minimal(base_size = 14) ``` ] .right-output-ggplot4a-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4a_rotate_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot4a-rotate[ ```r ggplot(data = j_data3) + * aes(x = reorder(Material, n), y = n) + geom_col() + scale_y_log10() + labs(x = "Raw Material", y = "Frequency") + theme_minimal(base_size = 14) ``` ] .right-output-ggplot4a-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot4a_rotate_2_output-1.png" width="432" /> ] <style> .left-code-ggplot4a-rotate { color: #777; width: 55%; height: 92%; float: left; font-size: 80% } .right-output-ggplot4a-rotate { width: 40%; float: right; padding-left: 1%; } </style> --- background-image: url(https://images.unsplash.com/photo-1556484658-6789c325bedf?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80) background-size: cover # Your turn --- background-image: url(https://images.unsplash.com/photo-1455849318743-b2233052fcff?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1650&q=80) background-size: cover # Your turn --- # Your turn ```r j_data3 <- j_data2 %>% group_by(Material) %>% tally() %>% arrange(desc(n)) %>% drop_na() ``` ```r ggplot(data = j_data3) + aes(x = Material, y = n) + geom_col() + scale_y_log10() + labs(x = "Raw Material", y = "Frequency") + theme_minimal(base_size = 14) ```
05
:
00
--- class: center, middle # What have we done? Verb | Plot ------------- | ------------- select ✅ | histogram ✅ filter ✅ | scatterplot ✅ mutate ✅ | boxplot ✅ group by ✅ | barplot ✅ summarise 🔜 | facet 🔜 --- class: split-40 count: false .left-code-dplyr5-auto[ ```r *j_data2 ``` ] .right-output-dplyr5-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5-auto[ ```r j_data2 %>% * group_by(Material) ``` ] .right-output-dplyr5-auto[ ``` # A tibble: 9,752 x 49 # Groups: Material [8] Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5-auto[ ```r j_data2 %>% group_by(Material) %>% * summarise(length_mean = mean(Length), * length_sd = sd(Length)) ``` ] .right-output-dplyr5-auto[ ``` # A tibble: 8 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert NA NA 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 8 <NA> NA NA ``` ] --- class: split-40 count: false .left-code-dplyr5-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length), length_sd = sd(Length)) ``` ] .right-output-dplyr5-auto[ ``` # A tibble: 8 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert NA NA 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 8 <NA> NA NA ``` ] <style> .left-code-dplyr5-auto { color: #777; width: 65%; height: 92%; float: left; font-size: 80% } .right-output-dplyr5-auto { width: 25%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-dplyr5a-auto[ ```r *j_data2 ``` ] .right-output-dplyr5a-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5a-auto[ ```r j_data2 %>% * group_by(Material) ``` ] .right-output-dplyr5a-auto[ ``` # A tibble: 9,752 x 49 # Groups: Material [8] Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5a-auto[ ```r j_data2 %>% group_by(Material) %>% * summarise(length_mean = mean(Length, na.rm = TRUE), * length_sd = sd(Length, na.rm = TRUE)) ``` ] .right-output-dplyr5a-auto[ ``` # A tibble: 8 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6.00 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 8 <NA> NaN NA ``` ] --- class: split-40 count: false .left-code-dplyr5a-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% * drop_na() ``` ] .right-output-dplyr5a-auto[ ``` # A tibble: 7 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6.00 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 ``` ] --- class: split-40 count: false .left-code-dplyr5a-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% drop_na() ``` ] .right-output-dplyr5a-auto[ ``` # A tibble: 7 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6.00 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 ``` ] <style> .left-code-dplyr5a-auto { color: #777; width: 70%; height: 92%; float: left; font-size: 80% } .right-output-dplyr5a-auto { width: 25%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r *j_data2 ``` ] .right-output-dplyr5b-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% * group_by(Material) ``` ] .right-output-dplyr5b-auto[ ``` # A tibble: 9,752 x 49 # Groups: Material [8] Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% group_by(Material) %>% * summarise(length_mean = mean(Length, na.rm = TRUE), * length_sd = sd(Length, na.rm = TRUE)) ``` ] .right-output-dplyr5b-auto[ ``` # A tibble: 8 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6.00 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 8 <NA> NaN NA ``` ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% * drop_na() ``` ] .right-output-dplyr5b-auto[ ``` # A tibble: 7 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6.00 2 Quartz 10.9 8.20 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.60 ``` ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% drop_na() %>% * mutate_if(is.numeric, round, 2) ``` ] .right-output-dplyr5b-auto[ ``` # A tibble: 7 x 3 Material length_mean length_sd <fct> <dbl> <dbl> 1 Chert 10.4 6 2 Quartz 10.9 8.2 3 Quartzite 14.9 8.83 4 Silcrete 11.0 5.28 5 Unknown 15.2 10.1 6 Volcanic 14.3 10.0 7 Other 13.2 5.6 ``` ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% drop_na() %>% mutate_if(is.numeric, round, 2) %>% * knitr::kable('html') ``` ] .right-output-dplyr5b-auto[ <table> <thead> <tr> <th style="text-align:left;"> Material </th> <th style="text-align:right;"> length_mean </th> <th style="text-align:right;"> length_sd </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Chert </td> <td style="text-align:right;"> 10.38 </td> <td style="text-align:right;"> 6.00 </td> </tr> <tr> <td style="text-align:left;"> Quartz </td> <td style="text-align:right;"> 10.94 </td> <td style="text-align:right;"> 8.20 </td> </tr> <tr> <td style="text-align:left;"> Quartzite </td> <td style="text-align:right;"> 14.90 </td> <td style="text-align:right;"> 8.83 </td> </tr> <tr> <td style="text-align:left;"> Silcrete </td> <td style="text-align:right;"> 11.02 </td> <td style="text-align:right;"> 5.28 </td> </tr> <tr> <td style="text-align:left;"> Unknown </td> <td style="text-align:right;"> 15.23 </td> <td style="text-align:right;"> 10.10 </td> </tr> <tr> <td style="text-align:left;"> Volcanic </td> <td style="text-align:right;"> 14.31 </td> <td style="text-align:right;"> 10.04 </td> </tr> <tr> <td style="text-align:left;"> Other </td> <td style="text-align:right;"> 13.16 </td> <td style="text-align:right;"> 5.60 </td> </tr> </tbody> </table> ] --- class: split-40 count: false .left-code-dplyr5b-auto[ ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% drop_na() %>% mutate_if(is.numeric, round, 2) %>% knitr::kable('html') ``` ] .right-output-dplyr5b-auto[ <table> <thead> <tr> <th style="text-align:left;"> Material </th> <th style="text-align:right;"> length_mean </th> <th style="text-align:right;"> length_sd </th> </tr> </thead> <tbody> <tr> <td style="text-align:left;"> Chert </td> <td style="text-align:right;"> 10.38 </td> <td style="text-align:right;"> 6.00 </td> </tr> <tr> <td style="text-align:left;"> Quartz </td> <td style="text-align:right;"> 10.94 </td> <td style="text-align:right;"> 8.20 </td> </tr> <tr> <td style="text-align:left;"> Quartzite </td> <td style="text-align:right;"> 14.90 </td> <td style="text-align:right;"> 8.83 </td> </tr> <tr> <td style="text-align:left;"> Silcrete </td> <td style="text-align:right;"> 11.02 </td> <td style="text-align:right;"> 5.28 </td> </tr> <tr> <td style="text-align:left;"> Unknown </td> <td style="text-align:right;"> 15.23 </td> <td style="text-align:right;"> 10.10 </td> </tr> <tr> <td style="text-align:left;"> Volcanic </td> <td style="text-align:right;"> 14.31 </td> <td style="text-align:right;"> 10.04 </td> </tr> <tr> <td style="text-align:left;"> Other </td> <td style="text-align:right;"> 13.16 </td> <td style="text-align:right;"> 5.60 </td> </tr> </tbody> </table> ] <style> .left-code-dplyr5b-auto { color: #777; width: 50%; height: 92%; float: left; font-size: 80% } .right-output-dplyr5b-auto { width: 45%; float: right; padding-left: 1%; } </style> --- class: center, middle # Let's make a facetted plot <img src="figures/noun_grid_2202247.png" style="display: inline-block; margin: 0" width="50px" height="50px" /> --- class: split-40 count: false .left-code-ggplot5-auto[ ```r *j_data2 ``` ] .right-output-ggplot5-auto[ ``` # A tibble: 9,752 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,742 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% * drop_na(Material) ``` ] .right-output-ggplot5-auto[ ``` # A tibble: 9,742 x 49 Site Square Spit Group Artno Material Colour Weight Length Artclas Cortex <chr> <chr> <dbl> <dbl> <dbl> <fct> <chr> <dbl> <dbl> <chr> <dbl> 1 J B 1 1 1 Chert Brown 1.83 22.0 Flake 0 2 J B 1 1 2 Chert Yellow 0.61 14.6 RetF 0 3 J B 1 1 3 Chert Dk Gr… 3.81 29.6 Core 0 4 J B 1 1 4 Chert Grey 0.13 5.83 RetFrag 0 5 J B 1 1 5 Chert Grey 0.05 7.07 Flake 0 6 J B 1 1 6 Chert Lt Br… 0.580 11.1 Core NA 7 J B 1 1 7 Chert Dk Br… 0.03 5.72 Flake 0 8 J B 1 1 8 Chert Cream 0.02 8.37 FFrag 0 9 J B 1 1 9 Chert Grey 0.21 10.7 Flake-b 0 10 J B 1 1 10 Chert Grey 0.25 14.3 Flake 0 # … with 9,732 more rows, and 38 more variables: Cortype <chr>, Initiat <chr>, # Breaks <chr>, Noseg <dbl>, Platwid <dbl>, Plat <chr>, Focal <lgl>, # Overhang <chr>, NoDS <dbl>, NoPS <dbl>, Rtch <chr>, Plat_2 <chr>, # Focal_2 <lgl>, Overhang_2 <chr>, NoDS_2 <dbl>, NoPS_2 <dbl>, Rtch_2 <chr>, # RetOri <chr>, Retype <chr>, Retloc <chr>, Retlen <dbl>, Retdep <dbl>, # Portion <chr>, Heat <dbl>, EdgeDam <dbl>, Weathering <dbl>, Corerot <dbl>, # RetScNo <dbl>, Term <chr>, Janus <lgl>, Recycled <lgl>, Redirect <lgl>, # Width <dbl>, Thick <dbl>, Platthic <dbl>, area <dbl>, elongation <dbl>, # plat_area <dbl> ``` ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% *ggplot() ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_3_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + * aes(x = Length) ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_4_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + * geom_histogram() ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_5_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + * facet_wrap( ~ Material) ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_6_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + facet_wrap( ~ Material) + * labs(x = "Length (mm)", * y = "Frequency") ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_7_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5-auto[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + facet_wrap( ~ Material) + labs(x = "Length (mm)", y = "Frequency") + * theme_minimal(base_size = 12) ``` ] .right-output-ggplot5-auto[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5_auto_8_output-1.png" width="432" /> ] <style> .left-code-ggplot5-auto { color: #777; width: 55%; height: 92%; float: left; font-size: 80% } .right-output-ggplot5-auto { width: 40%; float: right; padding-left: 1%; } </style> --- class: split-40 count: false .left-code-ggplot5a-rotate[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + facet_wrap( ~ Material) + labs(x = "Length (mm)", y = "Frequency") + theme_minimal(base_size = 12) ``` ] .right-output-ggplot5a-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5a_rotate_1_output-1.png" width="432" /> ] --- class: split-40 count: false .left-code-ggplot5a-rotate[ ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + * facet_wrap( ~ Material, scales = "free_y" ) + labs(x = "Length (mm)", y = "Frequency") + theme_minimal(base_size = 12) ``` ] .right-output-ggplot5a-rotate[ <img src="tidyverse-for-archaeology_files/figure-html/ggplot5a_rotate_2_output-1.png" width="432" /> ] <style> .left-code-ggplot5a-rotate { color: #777; width: 75%; height: 92%; float: left; font-size: 80% } .right-output-ggplot5a-rotate { width: 20%; float: right; padding-left: 1%; } </style> --- background-image: url(https://images.unsplash.com/photo-1565014237362-c52e04dcf6ad?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=976&q=80) background-size: cover # Your turn --- background-image: url(https://images.unsplash.com/photo-1533561797500-4fad4750814e?ixlib=rb-1.2.1&auto=format&fit=crop&w=934&q=80) background-size: cover # Your turn --- # Your turn ```r j_data2 %>% group_by(Material) %>% summarise(length_mean = mean(Length, na.rm = TRUE), length_sd = sd(Length, na.rm = TRUE)) %>% drop_na() ``` ```r j_data2 %>% drop_na(Material) %>% ggplot() + aes(x = Length) + geom_histogram() + facet_wrap( ~ Material, scales = "free_y" ) + labs(x = "Length (mm)", y = "Frequency") + theme_minimal(base_size = 12) ```
05
:
00
--- class: center, middle # What have we done? Verb | Plot ------------- | ------------- select âś… | histogram âś… filter âś… | scatterplot âś… mutate âś… | boxplot âś… group by âś… | barplot âś… summarise âś… | facet âś… --- background-image: url(figures/end.gif) background-size: cover --- class: inverse, middle, center The flipbooked portion of this presentation was created with the new {flipbookr} package. Get it with `remotes::install_github("EvaMaeRey/flipbookr")` ---