Add some labels to each country
A nice thing that can be added to plots are annotations or labels, so readers see the value of each data point displayed in the plot panel. This often makes axes obsolete, an advantage you're going to use in the last exercise of this chapter. These labels are usually added with geom_text()
or geom_label()
. The latter adds a background to each label, which is not needed here.
Cet exercice fait partie du cours
Communicating with Data in the Tidyverse
Instructions
- Label both points on the line with their respective working hours value. Use the
geom_text()
function for this, with the x- and y-aesthetic identical to the one in thegeom_path()
call. - Specify the
working_hours
variable for thelabel
argument. Roundworking_hours
to one digit after the decimal point.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
ggplot(ilo_data) +
geom_path(aes(x = working_hours, y = country),
arrow = arrow(length = unit(1.5, "mm"), type = "closed")) +
# Add a geom_text() geometry
___(
aes(x = ___,
y = ___,
label = round(___, 1))
)