As a next step, we will examine pie chart. In R, pie chart can be created by the following code:
data <- c(...)
label <- c(...)
pie(data, labels = label, main="title", init.angle=90)
Here, you put the numerical data in the data
vector and the labels in label
vector.
We will be visualizing COVID-19 deaths broken down by race.
df <- read.csv('Data/COVID-race.csv')
df
This data is from: https://www.cdc.gov/nchs/nvss/vsrr/covid19/health_disparities.htm
data <- df$Number
label <- df$Race
pie(data, labels = label, main="COVID-19 Deaths", init.angle=90)
We can add the percentages to the pie chart as well by using the following code:
data <- c(...)
label <- c(...)
per <- round(data/sum(data)*100) # get percentages
label <- paste(label, per, " %")
pie(data, labels = label, main="title", init.angle=90)
data <- df$Number
label <- df$Race
per <- round(data/sum(data)*100)
label <- paste(label, per, "%")
pie(data, labels = label, main="COVID-19 Deaths", init.angle=90)
We can change the fontsize of the labels by including cex=
argument inside the pie chart:
data <- df$Number
label <- df$Race
per <- round(data/sum(data)*100)
label <- paste(label, per, "%")
pie(data, labels = label, main="COVID-19 Deaths", init.angle=90, cex=0.7)
©2021 by Daiki Tagami. All rights reserved.