Skip to content

Commit

Permalink
Replace size with linewidth
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ndporter authored May 16, 2024
1 parent f3895e8 commit 68953ac
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions episodes/08-plot-ggplot2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
```

:::::::::::::::::::::::::
Expand Down Expand Up @@ -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)
```

:::::::::::::::::::::::::
Expand Down

0 comments on commit 68953ac

Please sign in to comment.