Introducing geometric objects

Geometric objects are elements that we mark on the plot. One can use the geometric object in ggplot2 to create either a line, bar, or box chart. Moreover, one can integrate these simple geometric objects and aesthetic mapping to create a more professional plot. In this recipe, we introduce how to use geometric objects to create various charts.

Getting ready

Ensure you have completed the previous steps by storing sample_sum in your R environment.

How to do it…

Perform the following steps to create a geometric object in ggplot2:

  1. First, create a scatterplot with the geom_point function:
    > g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Total_Sales, col=Province )) + ggtitle('Scatter Plot')
    > g + geom_point() 
    
  2. Use ...

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.