ggplot(data = gap_2007, aes(x = gdpPercap, y = lifeExp, color = continent)) +geom_point() +annotate("text", x =40000, y =73, label ="Countries with \nhigh GDP per capita and \nhigh life expectancy") +annotate("rect", xmin =30000, xmax =50000, ymin =75, ymax =83, alpha =0.2)
7 Labels and axes
7.1labs() layer
All the labels in the plot
Title, subtitle, caption
Legend title
X and Y axis labels
Still supports older versions: xlab(), ylab(), ggtitle()
7.2 Title and subtitle
ggplot(data = gap_2007, aes(x = gdpPercap, y = lifeExp, color = continent)) +geom_point() +labs(title ="This is the title",subtitle ="This is the subtitle",caption ="And here's a caption")
7.3 Title and subtitle
ggplot(data = gap_2007, aes(x = gdpPercap, y = lifeExp, color = continent)) +geom_point() +labs(title ="Scatterplot of life expectancy vs GDP per capita",subtitle ="There is a nonlinear relationship",caption ="Data: gapminder package, year 2007")