Changing aesthetics mapping

Aesthetics mapping describes how data variables are mapped to the visual property of a plot. In this recipe, we discuss how to modify aesthetics mapping on geometric objects.

Getting ready

Ensure you have installed and loaded ggplot2 into your R session. Also, you need to complete the previous steps by storing sample_sum in your R environment.

How to do it…

Please perform the following steps to add aesthetics to the plot:

  1. First, create a scatterplot by mapping Year_Month to the x axis, Total_Sales to the y axis, and Province to color:
    > g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Total_Sales, colour=Province)) + ggtitle('With geom_point')
    > g + geom_point()
    
  2. Set the aesthetics mapping on the geometric object: ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.