From 68953ac7db1a244c180cd4998c70f5e0e2484cce Mon Sep 17 00:00:00 2001 From: Nathaniel D Porter Date: Thu, 16 May 2024 09:08:45 -0400 Subject: [PATCH] Replace size with linewidth MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `size` with `linewidth` for `geom_smooth()` example. Using `size` for lines was deprecated per this error message: > > ggplot(data=gapminder, > + mapping=aes(x=gdpPercap, > + y=lifeExp)) + > + geom_point(alpha=0.5) + > + scale_x_log10() + > + geom_smooth(method='lm', size=1.5) > `geom_smooth()` using formula = 'y ~ x' > Warning message: > Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0. > ℹ Please use `linewidth` instead. > This warning is displayed once every 8 hours. > Call `lifecycle::last_lifecycle_warnings()` to see where this warning was generated. Change throughout the lesson and additionally: 1. Adjust language in explanations to match 2. Add hint to challenge clarifying size is point equivalent of linewidth. 3. Add some additional explanation of difference between aesthetics with vs without mappings. --- episodes/08-plot-ggplot2.Rmd | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/episodes/08-plot-ggplot2.Rmd b/episodes/08-plot-ggplot2.Rmd index 39d6683c5..19b4e087c 100644 --- a/episodes/08-plot-ggplot2.Rmd +++ b/episodes/08-plot-ggplot2.Rmd @@ -270,18 +270,15 @@ ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + geom_point(alpha = 0.5) + scale_x_log10() + geom_smooth(method="lm") ``` -We can make the line thicker by *setting* the **size** aesthetic in the +We can make the line thicker by *setting* the **linewidth** aesthetic in the `geom_smooth` layer: ```{r lm-fit2, fig.alt="Scatter plot of life expectancy vs GDP per capita with a trend line summarising the relationship between variables. The blue trend line is slightly thicker than in the previous figure."} ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + - geom_point(alpha = 0.5) + scale_x_log10() + geom_smooth(method="lm", size=1.5) + geom_point(alpha = 0.5) + scale_x_log10() + geom_smooth(method="lm", linewidth=1.5) ``` -There are two ways an *aesthetic* can be specified. Here we *set* the **size** -aesthetic by passing it as an argument to `geom_smooth`. Previously in the -lesson we've used the `aes` function to define a *mapping* between data -variables and their visual representation. +There are two ways an *aesthetic* can be specified. Here we *set* the **linewidth** aesthetic by passing it as an argument to `geom_smooth` and it is applied the same to the whole `geom`. Previously in the lesson we've used the `aes` function to define a *mapping* between data variables and their visual representation. ::::::::::::::::::::::::::::::::::::::: challenge @@ -292,6 +289,8 @@ example. Hint: do not use the `aes` function. +Hint: the equivalent of `linewidth` for points is `size`. + ::::::::::::::: solution ## Solution to challenge 4a @@ -304,7 +303,7 @@ a specific variable. ```{r ch4a-sol, fig.alt="Scatter plot of life expectancy vs GDP per capita with a trend line summarising the relationship between variables. The plot illustrates the possibilities for styling visualisations in ggplot2 with data points enlarged, coloured orange, and displayed without transparency."} ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp)) + geom_point(size=3, color="orange") + scale_x_log10() + - geom_smooth(method="lm", size=1.5) + geom_smooth(method="lm", linewidth=1.5) ``` ::::::::::::::::::::::::: @@ -332,7 +331,7 @@ is placed inside the `aes()` call modifies a point's color based on its continen ```{r ch4b-sol} ggplot(data = gapminder, mapping = aes(x = gdpPercap, y = lifeExp, color = continent)) + geom_point(size=3, shape=17) + scale_x_log10() + - geom_smooth(method="lm", size=1.5) + geom_smooth(method="lm", linewidth=1.5) ``` :::::::::::::::::::::::::