Get startedGet started for free

Exercise 14. Titles

In the previous exercises we created a plot using the following code:

library(dplyr)
library(ggplot2)
library(dslabs)
data(murders)
p<- murders %>% ggplot(aes(population, total, label = abb, color = region)) +
  geom_label()
p + scale_x_log10() + scale_y_log10()

We are now going to add a title to this plot. We will do this by adding yet another layer, this time with the function ggtitle.

This exercise is part of the course

Data Science Visualization - Module 2

View Course

Exercise instructions

Edit the code above to add the title "Gun murder data" to the plot.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

p <- murders %>% ggplot(aes(population, total, label = abb, color = region)) +
  geom_label()
# add a layer to add title to the next line
p + scale_x_log10() + 
    scale_y_log10()
Edit and Run Code