Hello and welcome! In today's lesson, we will venture into the world of Pie Charts in R. Pie charts are an elegant way to showcase proportions in relation to the total — for instance, illustrating populations by continents. Today, you will learn how to create and customize pie charts in R using the ggplot2
package.
Pie charts are a graphical representation in which a circle, or "the pie," is divided into individual "slices," each representing a category. Picture a pizza: each slice represents a distinct fruit type — apples, oranges, bananas, and grapes. The size of each piece represents the quantity of the fruit. We'll be using the versatile R data visualization library, ggplot2
, to generate interactive pie charts.
Let's create a pie chart that depicts the favorite fruits of a group of individuals. This could represent consumer preferences in a market study. Here's the dataset:
Let's start creating a pie chart for this dataset.
Pie Chart Components:
- Slices: Portions reflecting each fruit preference.
- Labels: Names of each type of fruit.
In crafting the Pie Chart with the ggplot2
library, we can create an informative and attractive pie chart. We'll first generate a bar plot and then use to convert it to a pie chart.
