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

A simple 3D pie chart


In Chapter 5, The Pie Chart and its Alternatives, we studied pie charts in great detail. In this recipe, we will focus on generating a 3D pie chart in R using the plotrix package.

Getting ready

In order to generate a 3D pie chart, we will use the plotrix package in R.

How to do it…

In order to plot a 3D pie chart in R, we will first install and load the plotrix package in R using the install.packages()and library() functions respectively:

install.packages("plotrix")
library(plotrix)

We have generated the 3D pie chart using traumatic brain injury data, also used in Chapter 5, The Pie Chart and its Alternatives. Please refer to the recipe Generating a simple pie chart from that chapter to understand the data transformation and further use of paste(). The following lines of code are used to construct our data and the code is explained in detail in chapter 5, The Pie Chart and its Alternatives:

data = c(179718,41370,41914,44280)
pct = (data/sum(data))*100
pct = round(pct,2)
labels...