All script is copied from Hadley Wickham’s Plotcon 2016 lecture. Video Link

Load library

Get Data

country continent year lifeExp pop gdpPercap
Afghanistan Asia 1952 28.801 8425333 779.4453
Afghanistan Asia 1957 30.332 9240934 820.8530
Afghanistan Asia 1962 31.997 10267083 853.1007
Afghanistan Asia 1967 34.020 11537966 836.1971
Afghanistan Asia 1972 36.088 13079460 739.9811
Afghanistan Asia 1977 38.438 14880372 786.1134

Nested data

year lifeExp pop gdpPercap year1950
1952 28.801 8425333 779.4453 2
1957 30.332 9240934 820.8530 7
1962 31.997 10267083 853.1007 12
1967 34.020 11537966 836.1971 17
1972 36.088 13079460 739.9811 22
1977 38.438 14880372 786.1134 27
year lifeExp pop gdpPercap year1950
1952 55.23 1282697 1601.056 2
1957 59.28 1476505 1942.284 7
1962 64.82 1728137 2312.889 12
1967 66.22 1984060 2760.197 17
1972 67.69 2263554 3313.422 22
1977 68.93 2509048 3533.004 27

Fit models

Broom

Unnest

## `geom_smooth()` using method = 'loess' and formula 'y ~ x'