4.12 Extra: Advanced examples

There are two examples of how just a few lines of ggplot() code and the basic geoms introduced in this chapter can be used to make very different things. Let your imagination fly free when using ggplot()!

The first one shows how the life expectancies in European countries have increased by plotting a square (geom_point(shape = 15)) for each observation (year) in the dataset.

In the second example, we’re using group_by(continent) followed by mutate(country_number = seq_along(country)) to create a new column with numbers 1, 2, 3, etc for countries within continents. We are then using these as y coordinates for the text labels (geom_text(aes(y = country_number...).