knitr::opts_chunk$set( collapse = TRUE, comment = "#>", message = FALSE, warning = FALSE )
This cookbook provides examples of the code used to produce various chart types using sgplot. There are also examples to demonstrate how to apply further customisation to sgplot charts.
If there is a chart type or task which you think would be useful to include here, please submit a suggestion.
use_sgplot
The examples in this cookbook use the sgplot theme and colour functions explicitly, however it may be easier to make use of the use_sgplot()
function if your charts all require a similar style. More information on use_sgplot
can be found on the homepage.
Note on use of titles, subtitles and captions
Titles, subtitles and captions have been embedded in the charts in this cookbook for demonstration purposes. However, for accessibility reasons, it is usually preferable to provide titles in the body of the page rather than embedded within the image of the plot.
The following packages are required to produce the example charts in this cookbook:
library(sgplot) library(ggplot2) library(dplyr) # Use gapminder data for cookbook charts library(gapminder)
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.