Pie Chart from Summarized Data

First, read Table6 into R.

Table6 <- read.csv("https://sullystats.github.io/Statistics6e/Data/Chapter2/Table6.csv")
Table6
##      Education X2017
## 1        No_HS 26582
## 2   HS_Diploma 60032
## 3 Some_College 45110
## 4   Associates 18761
## 5    Bachelors 43585
## 6    Grad_Prof 27181

Creating a pie chart from summarized data also requires some data manipulation.

Step 1: Before creating the pie chart, calculate the percentage of each slice. This step is only necessary if you want to see the percentages in the labels. The command is as follows:

piepercent <- round(tablequantatativecolumn/sum(tablequantatative_column)x100).

Step 2: : Following that command, use the following code to add a percent sign to the percentages:

piepercent <- paste(piepercent, “%”)

Step 3: Then you can write the necessary code to create a pie chart. Use the following command:

pie(table$quantatative_column, labels = piepercent)

Step 4: The next step is to add a legend to the pie chart. Use the following command:

legend(“location”, as.character(table$qualitative_column), fill = colors)

Notes:

piepercent <- round(Table6$X2017/sum(Table6$X2017)*100)
piepercent <- paste(piepercent,"%")
pie(Table6$X2017,labels=piepercent, main = "Pie Graph from Summarized Data", col = rainbow(length(Table6$X2017)))
legend("topright", as.character(Table6$Education), cex = 0.7, fill = rainbow(length(Table6$X2017)))