To give context to the data, add some value labels.
Sometimes you need to draw special attention to a few precise values in your data. They might be minimum or maximum values, or they might relate to a specific time or an interesting group. In such a situation, you can add value labels near corresponding points. This will make your reader direct their attention to whatever you want to highlight.
To add value labels, use geom_text()
as shown below:
geom_text(aes(x=position_x, y = position_y, label = value_labels), nudge_y=-.5, color="grey")
This command takes three main arguments: x sets the horizontal position of the label, y sets its vertical position, and label sets the displayed text. We have another argument here as well: nudge_y
, which nudges the labels in a vertical direction from the line (+0.5 up and -0.5 down). The final argument, color
, sets the color of the label's text.
In our line chart, we want to highlight the minimum and maximum values of the consumption
variable. The minimum value (1.68 litres per capita) was recorded in 2000 and the maximum (7.27 litres per capita) was recorded in 1984.
Remember that the x axis is now a time axis, so you have to use arguments in date format. Do this by specifying for example parse_date_time(2000, orders='Y')
.