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:
- First, create a scatterplot by mapping
Year_Month
to the x axis,Total_Sales
to the y axis, andProvince
to color:> g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Total_Sales, colour=Province)) + ggtitle('With geom_point') > g + geom_point()
- Set the aesthetics mapping on the geometric object:
> g2 <- ggplot(data=sample_sum) + geom_point(mapping=aes(x=Year_Month, y=Total_Sales, colour=Province)) + ggtitle('With Aesthetics Mapping') > g2