Besides deciding the visual property of a geometric object with aesthetic mapping, one can adjust the background color, grid lines, and other non-data properties with the theme. We introduce how to change the theme in this recipe.
Ensure you have completed the previous steps by storing sample_sum
in your R environment.
Please perform the following steps to adjust the theme in ggplot2
:
We can use different
theme
functions to adjust the theme of the plot:> g <- ggplot(data=sample_sum, mapping=aes(x=Year_Month, y=Total_Sales, colour = Province )) > g+geom_point(size=5) + theme_bw()+ ggtitle('theme_bw Example') > g+geom_point(size=5) + theme_dark()+ ggtitle('theme_dark Example')
We can set the theme freely with the
theme
function:> g +geom_point(size=5) + + theme( + axis.text = element_text(size = 12), + legend.background = element_rect(fill = "white"), + panel.grid.major = element_line...