Pie charts are a fast and easy way to visualize a single relationship within a dataset. Let us look at how to create a pie chart in R:
pie(...)
function to create a pie chart:> #create a pie chart that depicts the gold cost of the fire attack in relation to the total funds allotted to the Shu army > #get the data to be used in the chart > #what is the cost of the proposed fire attack? > functionGoldCost(2500, 225, 7) [1] 6791.667 > #we already know that 1,000,000 gold has been allotted to the Shu army > #therefore our remaining funds after the fire attack would be 993,208 > #create a vector to hold the values for the chart's slices > pieFireGoldCostSlices <- c(6792, 993208) > #use the labels argument to specify the text associated with each of the chart's slices > pieFireGoldCostLabels <- c("mission cost", "remaining funds") > #customize the chart > pieFireGoldCostMain <- "Gold Cost of Fire Attack" > pieFireGoldCostSpecificColors <- c("green", "blue") > #use pie(...) to create and display the pie chart > pie(x = pieFireGoldCostSlices, labels = pieFireGoldCostLabels, main = pieFireGoldCostMain, col = pieFireGoldCostSpecificColors)
> #use the legend(...) function to add a legend to the chart > legend(x = "bottom", legend = pieFireGoldCostLabels, fill = pieFireGoldCostSpecificColors)