R Data Visualisation Example using R Base function

Create Demo dataset to be used for a plot.

# load a built in dataset e.g. iris flower dataset
head(VADeaths, 10)
##       Rural Male Rural Female Urban Male Urban Female
## 50-54       11.7          8.7       15.4          8.4
## 55-59       18.1         11.7       24.3         13.6
## 60-64       26.9         20.3       37.0         19.3
## 65-69       41.0         30.9       54.6         35.1
## 70-74       66.0         54.3       71.1         50.0
x <- VADeaths[1:5, "Rural Male"]
x
## 50-54 55-59 60-64 65-69 70-74 
##  11.7  18.1  26.9  41.0  66.0
df <- data.frame(
  group = c("Male", "Female", "Child"),
  value = c(25, 35, 40)
  )
df
##    group value
## 1   Male    25
## 2 Female    35
## 3  Child    40

Basic plots

pie(x, labels = names(x), radius = 0.8)

pie(df$value, labels = df$group, radius = 1)

# Change colors
pie(df$value, labels = df$group, radius = 1,
    col = c("#999999", "#E69F00", "#56B4E9"))

# 3D pie chart
library("plotrix")
pie3D(df$value, labels = df$group, radius = 1.5, 
      col = c("#999999", "#E69F00", "#56B4E9"))

# Explode the pie chart
pie3D(df$value, labels = df$group, radius = 1.5,
      col = c("#999999", "#E69F00", "#56B4E9"),
      explode = 0.1)