An Introduction to patternplot Package

Introduction

Currently in R, pie charts generated by functions pie() in package graphics, pie3D() in package plotrix, or coord_polar() in package ggplot2 can only have color coded slices. There are no R functions that have the capacity of filling pie chart slices with patterns. The patternplot package is a tool for creating aesthetically pleasing and informative pie charts in R. It can plot either black and white pie charts or pie charts in colors, with or without filled patterns. Black and white pie charts filled with patterns are useful for publications, especially when an increasing number of journals only accept black and white figures or charges a significant amount for a color figure. On the other hand, colorful pie charts with or without patterns are useful for print design, online publishing, or poster and PowerPoint presentations. patternplot allows the flexibility of a variety of combinations of patterns and colors to choose from. It also has the ability to fill in the slices with any external images in png and jpeg formats. In summary, patternplot allows the users to be as creative as they can while creating pie charts!

Pie charts in black and white

A simple example to start with.

library(patternplot)
group<-c('A', 'B', 'C', 'D', 'E')
pct<-c(20, 20, 20, 20, 20)
label<-paste(group, ' ',pct,'%', sep='' )
pattern.type<-c('hlines','nelines', 'grid', 'dots', 'nwlines')
p<-patternpie(group=group,pct=pct,label =label, pattern.type=pattern.type, pattern.line.size=0.5, pixel=1)
p

plot of chunk e1

No patterns, just gray scale.

pattern.type<-rep('blank',5)
background.color<-c('gray100','gray75', 'gray50', 'gray25', 'gray0')
p<-patternpie(group=group,pct=pct,label =label, pattern.type=pattern.type, background.color=background.color, pixel=1)
p

plot of chunk e2

Pie charts in colors

Change background colors and pattern colors.

pattern.type<-c('hlines','nelines', 'grid', 'dots', 'nwlines')
background.color<-c('yellow', 'orange','blue', 'violet', 'green')
pattern.color<-c('white', 'white','white', 'red', 'white')
p<-patternpie(group,pct,label,label.size=4, label.color='black',label.distance=1.2,pattern.type=pattern.type, pattern.color=pattern.color,
                  pattern.line.size=1, background.color=background.color, frame.color='black',frame.size=1, pixel=1)
p

plot of chunk e3

Change frame color.

frame.color<-'white'
p<-patternpie(group,pct,label,label.size=4, label.color='black',label.distance=1.2,pattern.type=pattern.type, pattern.color=pattern.color,
                  pattern.line.size=1, background.color=background.color, frame.color=frame.color,frame.size=1, pixel=1)
p

plot of chunk e4

No patterns, just colors.

pattern.type<-rep('blank',5)
background.color<-c('yellow', 'orange','blue', 'violet', 'green')
p<-patternpie(group=group,pct=pct,label =label, pattern.type=pattern.type, background.color=background.color, frame.color='white', pixel=1)
p

plot of chunk e5

Fill slices with png and jpeg images

Fill slices with png images.

#Fill slices with png images.
library(png)
Lines <-  readPNG(system.file("img", "lines.png", package="patternplot"))
Chessboard <-  readPNG(system.file("img", "chessboard.png", package="patternplot"))
Dots <-  readPNG(system.file("img", "dots.png", package="patternplot"))

pattern.type<-list(Chessboard, Lines,Dots)
group<-c('chessboard','Lines',  'Dots')
pct<-c(25, 40,  35)
label<-c("Chessboard 25% ", "Lines 40%",  "Dots 35%")

p<-imagepie(group=group,pct=pct,label=label,pattern.type=pattern.type,label.distance=1.35, 
              frame.color='black')
p

plot of chunk e6

Fill slices with jpeg images.

library(jpeg)
Tomatoes <-  readJPEG(system.file("img", "tomatoes.jpg", package="patternplot"))
Peas <- readJPEG(system.file("img", "peas.jpg", package="patternplot"))
Peppers <-  readJPEG(system.file("img", "peppers.jpg", package="patternplot"))

pattern.type<-list(Tomatoes,Peas,Peppers)
group<-c('Tomatoes', 'Peas', 'Peppers')
pct<-c(40, 25, 35)
label<-c("Tomatoes \n 40%", "Peas \n 25% ", "Peppers \n 35%")

p<-imagepie(group=group,pct=pct,label=label,pattern.type=pattern.type,label.distance=1.35, 
              frame.color='burlywood4', frame.size=0.8, label.size=6, label.color='forestgreen')
p

plot of chunk e7

h