Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Communicating with Data in the Tidyverse

Cursus bekijken

Oefeninstructies

  • 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 the geom_path() call.
  • Specify the working_hours variable for the label argument. Round working_hours to one digit after the decimal point.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

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))
        )
Code bewerken en uitvoeren