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

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