1. A custom plot to emphasize change
Great job! From the plot you just produced we see that there was a negative correlation between working hours and hourly compensation also in 1996.
2. <<<New Slide>>>
However, some countries seem to have shifted their position. In 2006, there are more countries with higher hourly compensation, and also more with less weekly working hours.
From this scatter plot, we can't really tell which countries have made the biggest shift.
3. The dot plot
A good visualization form for showing change over time in one variable is the so-called dot plot. It is often used in data journalism for comparing the change of different entities like countries. Here's an example from the New York Times, which shows what share of the overall national income the richest 1 percent have got.
For example, around 1980, the richest 1 percent in the US had 11 percent of the national income – nowadays they've got 20 percent. The dot plot not only shows which country made the biggest step into any direction, it also shows us the values for both years that are compared.
Thus, it is well suited to showing change over time while also presenting some sort of rank between items.
4. Dot plots with ggplot2
Dot plots can be easily created in ggplot2. Now, while there is a specific geometry called geom_dotplot, it's actually not what we are looking for. geom_dotplot basically produces a histogram with dots, as you can see in the code example here. The y axis now shows the share of countries with specific working hours, while the dots represent the actual countries in each category.
The terminology in data vis is not sacred, so different things can have same names. For the dot plot you are going to produce in the next exercises, you will use ggplot2's geom_path function.
5. The geom_path() function
geom_path is useful for creating plots based on fundamental geometric elements, such as lines. If you look at the help for geom_path, it tells you that it connects the observations in a data set in the order in which they appear. Let's have a look at your current data set.
In the first exercise of this chapter, you filtered it to only contain the years 1996 and 2006. If you order that data frame by country, you see that there are two rows for each country, representing both years. 1996 always comes before 2006, so geom_path will draw a path from 1996 to 2006, as these years appear in the data set.
6. Dot plots with `ggplot2`: the `geom_path()` function
geom_path requires the x- and y-aesthetic to be set. Both can be numeric variables, so geom_path will draw a path in the two-dimensional plane. However, one of both can also be a factor variable. If you specify a numeric variable for the x-aesthetic, and a factor for the y-aesthetic, geom_path will draw a single path for each value in the y-aesthetic, that is, for each value of the factor variable.
Also, you can add an arrow to each path, using the arrow argument outside the aesthetics function. The arrow argument in turn takes an arrow function call, where you can specify the type of the arrow head and other settings. The arrow will be placed at the last section of your path and thus point into the same direction the path was drawn.
7. Let's try out geom_path!
This may sound a bit theoretical, so let's look at a concrete example and build your first iteration of the dot plot.