Start by loading the dplyr and ggplot2 library as well as the murders data.

library(dplyr)
library(ggplot2)
library(dslabs)
data(murders)

If instead of points we want to add text, we can use the geom_text() or geom_label() geometries. The following code:

murders %>% ggplot(aes(population, total)) + geom_label()

will give us the error message:

Error: geom_label requires the following missing aesthetics: label

This is because we need to specify which labels it should print by the label aestethic mapping.

Exercise

  1. Extend the code from the example to use abbreviation (abb) as the label using aes. Save the resulting ggplot object in p_abb.

  2. Extend the code from question 1 to make ALL the labels blue. Save the resulting ggplot object in p_abb_blue.

  3. Extend the code from question 1 to make the labels color be determined by the state’s region. Store the resulting ggplot object in p_abb_colored.