Adjusting scales
Besides setting aesthetic mapping for each plot or geometric object, one can use scale to control how variables are mapped to the visual property. In this recipe, we introduce how to adjust the scale of aesthetics in ggplot2
.
Getting ready
Ensure you have completed the previous steps by storing sample_mean
in your R environment.
How to do it…
Perform the following steps to adjust the scale of aesthetic magnitude in ggplot2
:
First, make a scatterplot by setting
size=Total_Sales
,colour=Province
,y=Province
, and conditional onYear_Month
. Resize the point with thescale_size_continuous
function:> g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Province, size=Total_Sales, colour = Province )) > g + geom_point(aes(size=Total_Sales)) + scale_size_continuous(range=c(1,10)) + ggtitle('Resize The Point')
Repaint the point in gradient color with the
scale_color_gradient
function:> g + geom_point(aes(colour=Total_Sales)) + scale_color_gradient()+ ggtitle('Repaint...