From f997393f7b88960631f5166eb3d67f7a8d2e885f Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Tue, 25 Jun 2024 08:07:01 -0500 Subject: [PATCH] Cohort3 (#49) * Add new cohort to README. * Update TOC to match current book. * Disable broken blocks. * Use latest R version. --- .github/workflows/deploy_bookdown.yml | 2 -- .github/workflows/pr_check.yml | 2 -- 01-introduction.Rmd | 2 ++ 03-0.Rmd | 21 ------------- 03-individual_geoms.Rmd | 2 ++ 10-Position_scales_and_axes.Rmd | 2 ++ 11-Colour_scales_and_legends.Rmd | 3 +- 12-Other_aesthetics.Rmd | 30 ++++--------------- 14-build-plot.Rmd => 13-build-plot.Rmd | 2 ++ ...and-guides.Rmd => 14-Scales-and-guides.Rmd | 0 ...e-systems.Rmd => 15-Coordinate-systems.Rmd | 0 17-Faceting.Rmd => 16-Faceting.Rmd | 0 18-themes.Rmd => 17-themes.Rmd | 0 ...ot2.Rmd => 18-Programming-with-ggplot2.Rmd | 3 +- ...-internals.Rmd => 19-ggplot2-internals.Rmd | 6 ++-- ...ng-ggplot2.Rmd => 20-Extending-ggplot2.Rmd | 0 22-Case-Study.Rmd => 21-Case-Study.Rmd | 0 ...rammar.Rmd => 99-Mastering-the-Grammar.Rmd | 4 ++- README.md | 1 + 19 files changed, 24 insertions(+), 56 deletions(-) delete mode 100644 03-0.Rmd rename 14-build-plot.Rmd => 13-build-plot.Rmd (99%) rename 15-Scales-and-guides.Rmd => 14-Scales-and-guides.Rmd (100%) rename 16-Coordinate-systems.Rmd => 15-Coordinate-systems.Rmd (100%) rename 17-Faceting.Rmd => 16-Faceting.Rmd (100%) rename 18-themes.Rmd => 17-themes.Rmd (100%) rename 19-Programming-with-ggplot2.Rmd => 18-Programming-with-ggplot2.Rmd (99%) rename 20-ggplot2-internals.Rmd => 19-ggplot2-internals.Rmd (99%) rename 21-Extending-ggplot2.Rmd => 20-Extending-ggplot2.Rmd (100%) rename 22-Case-Study.Rmd => 21-Case-Study.Rmd (100%) rename 13-Mastering-the-Grammar.Rmd => 99-Mastering-the-Grammar.Rmd (98%) diff --git a/.github/workflows/deploy_bookdown.yml b/.github/workflows/deploy_bookdown.yml index 6e78e59..c38b129 100644 --- a/.github/workflows/deploy_bookdown.yml +++ b/.github/workflows/deploy_bookdown.yml @@ -14,8 +14,6 @@ jobs: steps: - uses: actions/checkout@v2 - uses: r-lib/actions/setup-r@v2 - with: - r-version: '4.2.0' - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index 1fdda39..4b57a53 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -13,8 +13,6 @@ jobs: steps: - uses: actions/checkout@v2 - uses: r-lib/actions/setup-r@v2 - with: - r-version: '4.2.1' - uses: r-lib/actions/setup-pandoc@v2 - uses: r-lib/actions/setup-r-dependencies@v2 with: diff --git a/01-introduction.Rmd b/01-introduction.Rmd index 61643ff..ab88db6 100644 --- a/01-introduction.Rmd +++ b/01-introduction.Rmd @@ -1,3 +1,5 @@ +# (PART\*) Getting Started {-} + # Introduction **Learning objectives:** diff --git a/03-0.Rmd b/03-0.Rmd deleted file mode 100644 index 93a4538..0000000 --- a/03-0.Rmd +++ /dev/null @@ -1,21 +0,0 @@ -# Layers {-} - -*Introduction* - -- Based on the *Grammar of Graphics*, GGplot2 encourages you to build plots in a structured manner building upon on your plots with various layers. -- The purposes of the layers are: -- to display the **data**. -- to display a **statistical summary** of the data. -- to add **metadata** such as context, annotations or references to your plot. - -## Layers: Chapters {-} - -**The section on layers is broken up into the following chapters:** - -- Chapter 3. Individual Geoms -- Chapter 4. Collective Geoms -- Chapter 5. Statistical Summaries -- Chapter 6. Maps -- Chapter 7. Networks -- Chapter 8. Annotations -- Chapter 9. Arranging Plots diff --git a/03-individual_geoms.Rmd b/03-individual_geoms.Rmd index b871b70..a6932a2 100644 --- a/03-individual_geoms.Rmd +++ b/03-individual_geoms.Rmd @@ -1,3 +1,5 @@ +# (PART\*) Layers {-} + # Individual Geoms ```{r 03-individualgeoms, include=FALSE} diff --git a/10-Position_scales_and_axes.Rmd b/10-Position_scales_and_axes.Rmd index 9cc968d..97f0dab 100644 --- a/10-Position_scales_and_axes.Rmd +++ b/10-Position_scales_and_axes.Rmd @@ -1,3 +1,5 @@ +# (PART\*) Scales {-} + # Position scales and axes **Learning Objectives** diff --git a/11-Colour_scales_and_legends.Rmd b/11-Colour_scales_and_legends.Rmd index 8c0d1f5..51e822f 100644 --- a/11-Colour_scales_and_legends.Rmd +++ b/11-Colour_scales_and_legends.Rmd @@ -1,10 +1,9 @@ # Colour Scales and Legends ```{r 11-library, include=FALSE} - library(ggplot2) library(dplyr) - +library(scico) ``` diff --git a/12-Other_aesthetics.Rmd b/12-Other_aesthetics.Rmd index 3a48e60..cf4fcac 100644 --- a/12-Other_aesthetics.Rmd +++ b/12-Other_aesthetics.Rmd @@ -15,12 +15,8 @@ To learn about several other aesthetics that ggplot2 can use to represent data, - identity scales - - ```{r 12-library 01, include=FALSE} - library(ggplot2) - ``` @@ -35,7 +31,6 @@ base <- ggplot(mpg, aes(displ, hwy, size = cyl)) + base base + scale_size(range = c(1, 2)) - ``` There are several size scales: @@ -54,7 +49,7 @@ There are several size scales: There are situations where area scaling is undesirable, and for such situations *scale_radius()* may be more appropriate. For example, consider a data set containing astronomical data that includes the radius of different planets: -```{r radius size scales 01, echo=FALSE } +```{r radius size scales 01, echo = FALSE} planets <- data.frame( name = c("Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"), type = c(rep("Inner", 4), rep("Outer", 4)), @@ -87,25 +82,19 @@ Binned size scales work similarly to binned scales for colour and position aesth ```{r binned size scales 01} - base <- ggplot(mpg, aes(displ, manufacturer, size = hwy)) + geom_point(alpha = .2) + scale_size_binned() base - ``` Unlike *guide_legend()*, the guide created for a binned scale by *guide_bins()* does not organize the individual keys into a table. Instead they are arranged in a column (or row) along a single vertical (or horizontal) axis, which by default is displayed with its own axis. The important arguments to guide_bins() are listed below: - **axis** indicates whether the axis should be drawn (default is TRUE) - - ```{r binned size scales 02} - base + guides(size = guide_bins(axis = FALSE)) - ``` - **direction** is a character string specifying the direction of the guide, either "vertical" (the default) or "horizontal" @@ -149,13 +138,11 @@ The default *scale_shape()* function contains a single argument: **set solid = T ```{r shape 01} - base <- ggplot(mpg, aes(displ, hwy, shape = factor(cyl))) + geom_point() base base + scale_shape(solid = FALSE) - ``` @@ -176,10 +163,8 @@ It is possible to map a variable onto the linetype aesthetic, which works best f ```{r line type 01} - ggplot(economics_long, aes(date, value01, linetype = variable)) + geom_line() - ``` With five categories the above plot is quite difficult to read. @@ -187,7 +172,6 @@ With five categories the above plot is quite difficult to read. The default “palette” for linetype is supplied by the *scales::linetype_pal()* function, and includes the 13 linetypes shown below: - ```{r line types 02} df <- data.frame(value = letters[1:13]) base <- ggplot(df, aes(linetype = value)) + @@ -211,7 +195,8 @@ This allows you to specify your own line types using *scale_linetype_manual()*, Note that the last four lines are blank, because the *linetypes()* function defined above returns NA when the number of categories exceeds 9. -```{r line types 03} +```{r line types 03, eval = FALSE} +# TODO: Eval turned off due to error, you should fix this! linetypes <- function(n) { types <- c("55", "75", "95", "1115", "111115", "11111115", "5158", "9198", "c1c8") @@ -227,7 +212,8 @@ The *scale_linetype()* function contains a na.value argument used to specify wha -```{r line types 04} +```{r line types 04, eval = FALSE} +# TODO: Eval turned off due to error, you should fix this! base + scale_linetype(palette = linetypes, na.value = "dotted") ``` @@ -262,23 +248,17 @@ ggplot(huron, aes(year)) + ggplot(huron, aes(year)) + geom_line(aes(y = level + 5, colour = "above")) + geom_line(aes(y = level - 5, colour = "below")) - - ``` - And then tell the scale how to map labels to colours: - - ```{r manual scales 03} - ggplot(huron, aes(year)) + geom_line(aes(y = level + 5, colour = "above")) + geom_line(aes(y = level - 5, colour = "below")) + scale_colour_manual("Direction", values = c("above" = "red", "below" = "blue") ) - ``` diff --git a/14-build-plot.Rmd b/13-build-plot.Rmd similarity index 99% rename from 14-build-plot.Rmd rename to 13-build-plot.Rmd index 3d92a39..5b94764 100644 --- a/14-build-plot.Rmd +++ b/13-build-plot.Rmd @@ -1,3 +1,5 @@ +# (PART\*) The Grammar {-} + # Build a plot layer by layer **Learning objectives:** diff --git a/15-Scales-and-guides.Rmd b/14-Scales-and-guides.Rmd similarity index 100% rename from 15-Scales-and-guides.Rmd rename to 14-Scales-and-guides.Rmd diff --git a/16-Coordinate-systems.Rmd b/15-Coordinate-systems.Rmd similarity index 100% rename from 16-Coordinate-systems.Rmd rename to 15-Coordinate-systems.Rmd diff --git a/17-Faceting.Rmd b/16-Faceting.Rmd similarity index 100% rename from 17-Faceting.Rmd rename to 16-Faceting.Rmd diff --git a/18-themes.Rmd b/17-themes.Rmd similarity index 100% rename from 18-themes.Rmd rename to 17-themes.Rmd diff --git a/19-Programming-with-ggplot2.Rmd b/18-Programming-with-ggplot2.Rmd similarity index 99% rename from 19-Programming-with-ggplot2.Rmd rename to 18-Programming-with-ggplot2.Rmd index 547605a..d1c6559 100644 --- a/19-Programming-with-ggplot2.Rmd +++ b/18-Programming-with-ggplot2.Rmd @@ -1,5 +1,6 @@ -# Programming with ggplot2 +# (PART\*) Advanced Topics {-} +# Programming with ggplot2 **Learning objectives:** diff --git a/20-ggplot2-internals.Rmd b/19-ggplot2-internals.Rmd similarity index 99% rename from 20-ggplot2-internals.Rmd rename to 19-ggplot2-internals.Rmd index 9baf796..0a1c8c3 100644 --- a/20-ggplot2-internals.Rmd +++ b/19-ggplot2-internals.Rmd @@ -662,14 +662,16 @@ p + This is the output of the `guide_train()` method defined for `guide_legend()`. The most important piece of it is `key`, which is the data associated with the legend. -```{r 20-57} +```{r 20-57, eval = FALSE} +# TODO: The unexported function no longer exists, so we had to turn off eval. names( ggtrace_inspect_return(p, ggplot2:::guide_train.legend) ) ggtrace_inspect_return(p, ggplot2:::guide_train.legend)$key ``` The output of `guide_train()` is passed to `guide_gengrob()`. This is the output of the `guide_gebgrob()` method defined for `guide_legend()`: -```{r 20-58} +```{r 20-58, eval = FALSE} +# TODO: The unexported function no longer exists, so we had to turn off eval. legend_gengrob <- ggtrace_inspect_return(p, ggplot2:::guide_gengrob.legend) grid.newpage() grid.draw(legend_gengrob) diff --git a/21-Extending-ggplot2.Rmd b/20-Extending-ggplot2.Rmd similarity index 100% rename from 21-Extending-ggplot2.Rmd rename to 20-Extending-ggplot2.Rmd diff --git a/22-Case-Study.Rmd b/21-Case-Study.Rmd similarity index 100% rename from 22-Case-Study.Rmd rename to 21-Case-Study.Rmd diff --git a/13-Mastering-the-Grammar.Rmd b/99-Mastering-the-Grammar.Rmd similarity index 98% rename from 13-Mastering-the-Grammar.Rmd rename to 99-Mastering-the-Grammar.Rmd index 08046b1..b0f283c 100644 --- a/13-Mastering-the-Grammar.Rmd +++ b/99-Mastering-the-Grammar.Rmd @@ -1,6 +1,8 @@ # Mastering the Grammar -```{r setup, include=FALSE} +***This was previously covered as chapter 13, but it does not exist as a separate chapter in the current version of the book.*** + +```{r 99-setup, include=FALSE} #library(knitr) #knitr::opts_chunk$set(cache=TRUE, cache.lazy= FALSE, warning = FALSE, diff --git a/README.md b/README.md index a62e7a3..0125a83 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ If you would like to present, please see the sign-up sheet for your cohort (link - Cohort 1 (started 2021-08-30, ended 2022-07-18): [meeting videos](https://www.youtube.com/playlist?list=PL3x6DOfs2NGhUxGvu46tXQtBl0qyTcDet) - Cohort 2 (started 2023-04-06, ended 2024-01-19): [meeting videos](https://youtube.com/playlist?list=PL3x6DOfs2NGhw3rkmaGipc21j0a7sCPNy) +- [Cohort 3](https://docs.google.com/spreadsheets/d/1vMD-FxWj9YakVAngHg67ctRVc0izzCu81L_UoaOSWqM/edit?usp=sharing) (starts 2024-07-10): [meeting videos](https://www.youtube.com/playlist?list=PL3x6DOfs2NGi0FPmGOBAeU1LRNp4lRC9-) ## How to Present