Creating a labeled scatter plot in R with ggplot2 (CC157)

October 25, 2021 • PD Schloss • 1 min read

A labeled scatter plot is an effective approach when you want to highlight something about data that you are measuring with two continuous variables. In this episode of Code Club, Pat shows how he would convert a slope chart into a labelled scatter plot to display the change in people’s intention to receive the COVID-19 vaccine with data from 2020. He uses geom_point from ggplot2 to create the scatter plot and then shows how to add labels using geom_label or geom_label_repel (from ggrepel). Finally, he also uses geom_abline, coord_fixed, and geom_text to create a legend. The data depict the percentage of people in 15 countries who would be willing to receive the COVID-19 vaccine as of August and October of 2020.

Code

You can browse the state of the demo at the

Data

The august_october_2020.csv data is available in the GitHub repository.

X.1,Total Agree - August 2020,Total Agree - October 2020
Total,77,73
India,87,87
China,97,85
South Korea,84,83
Brazil,88,81
Australia,88,79
United Kingdom,85,79
Mexico,75,78
Canada,76,76
Germany,67,69
Japan,75,69
South Africa,64,68
Italy,67,65
Spain,72,64
United States,67,64
France,59,54
comments powered by Disqus