Pie charts are universally used to display the exact proportion of categorical data.
They brilliantly slice a circle into pieces, where each piece represents a strict percentage of the whole dataset!
Instead of the standard plot() command, pie charts require the dedicated pie() function.
You simply pass a vector of numbers into it, and R mathematically calculates the exact slice angles automatically.
By default, R draws the first slice starting at exactly 3 o'clock and moves entirely counter-clockwise.
# Defining the values for the slices
market_share <- c(50, 25, 25)
# Adding descriptive labels
brands <- c("Apple", "Samsung", "Google")
# Generating the pie chart
pie(market_share, labels = brands, main = "Phone Market Share")
A black-and-white pie chart is incredibly difficult to read effectively.
You can pass a custom vector of vibrant colors into the col parameter to colorize every individual slice!
Furthermore, if you want the first slice to start at 12 o'clock (the top), you use the init.angle = 90 parameter.
# Re-defining the data for this example
market_share <- c(50, 25, 25)
brands <- c("Apple", "Samsung", "Google")
colors <- c("blue", "green", "orange")
pie(market_share,
labels = brands,
col = colors,
init.angle = 90)
Which specific function must you use to successfully render a pie chart in base R?
Which parameter dynamically forces the very first pie slice to start drawing directly from the top (12 o'clock)?