Book Image

R Graphs Cookbook Second Edition

Book Image

R Graphs Cookbook Second Edition

Overview of this book

Table of Contents (22 chapters)
R Graphs Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Making better, readable pie charts with clockwise-ordered slices


Pie charts are very popular in business data reporting. However, they are not preferred by scientists and are often criticized for being hard to read and obscuring data. In this recipe, we will learn how to make better pie charts by ordering the slices by size.

Getting ready

In this recipe, we will use the browsers.txt example dataset that contains data about the usage percentage share of different Internet browsers.

How to do it...

First, we will load the browsers.txt dataset and then use the pie() function to draw a pie chart:

browsers<-read.table("browsers.txt",header=TRUE)
browsers<-browsers[order(browsers[,2]),]

pie(browsers[,2],
labels=browsers[,1],
clockwise=TRUE,
radius=1,
col=brewer.pal(7,"Set1"),
border="white",
main="Percentage Share of Internet Browser usage")

How it works...

The important thing about the graph is that the slices are ordered in the ascending order of their sizes. We have done this because one of...