To highlight data context, add labels to the plot.
The main goal of the scatter plot is to show trends, not specific points. To detail-oriented readers, scatter plots can appear like nothing more than a bunch of dots. To make the scatter plot more detailed, interesting, and understandable, we can highlight some distinctive points.
What will we highlight? There are several possibilities, including:
- Extreme points – The minimum and maximum of both variables
- Untypical points – One or more "outlier" points that stand out from the main bunch
- Specific points – One or more points that add context to the data
In this case, we can focus on one particular country and highlight it on the chart by changing its point color and adding a label. To do that, we'll use two geometry commands: geom_text
and geom_point
.
First, add the country name to the data point using geom_text
:
+ geom_text( data = subset(alcohol_wealth, country == "Spain"), aes(label=country), color="red", nudge_x = 0.1, nudge_y =-0.5 )
We've annotated the data for Spain, putting its name (enclosed in double quotes) in the data
argument:
subset(alcohol_wealth, country == "Spain")
This will choose rows in the alcohol_wealth
dataset where the country
is equal to "Spain". The rest of the arguments change the color of the text and put it under the point.
Next, we'll change the color of the corresponding dot. To do that, add the following command:
+ geom_point( data = subset(alcohol_wealth, country == "Spain"), color="red")
This uses similar syntax to highlight the appropriate row.