Book Image

R Data Visualization Cookbook

By : Gohil
Book Image

R Data Visualization Cookbook

By: Gohil

Overview of this book

If you are a data journalist, academician, student or freelance designer who wants to learn about data visualization, this book is for you. Basic knowledge of R programming is expected.
Table of Contents (12 chapters)
11
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.

Generating an XKCD-style plot

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...