Book Image

R Data Visualization Cookbook

Book Image

R Data Visualization Cookbook

Overview of this book

Table of Contents (17 chapters)
R Data Visualization Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Generating an XKCD-style plot


If you have never read or seen xkcd cartoon strips, then I would highly recommend that you do. Some of the humor is sarcastic and entertaining. The idea behind generating an XKCD-style plot is to bring the same humor to our plot and try to make our visualization convey an idea or a story which is interesting and entertaining.

Getting ready

To create a chart, we require to install the following packages:

  • xkcd

  • ggplot2

How to do it…

We will install the two required packages and load them in our active R session using the install.packages()and library() functions:

install.packages(c("xkcd","ggplot2"))
windowsFonts(xk = windowsFont("xkcd"))
library(xkcd)
library(ggplot2)

The windowsFonts() function allows us to customize our fonts in R:

windowsFonts(xk = windowsFont("xkcd"))

In order to create a theme, we use the theme() function in ggplot2. Note that our aim in this recipe is to understand ways to generate xkcd plots. Users can refer to the ggplot2 manual for more clarification...