Pie Charts
Explore how to create pie charts in R using the pie() function and ggplot2. Learn to represent numerical proportions visually, customize slice colors, angles, shading, and add titles. This lesson helps you understand how to visualize categorical data effectively with pie charts for clear insights.
We'll cover the following...
Features
A pie chart is a circular statistical graphic, which is divided into slices to illustrate numerical proportions. Each slice in a pie chart represents a proportion or percentage of the whole. We use pie charts to visualize the relative sizes of different categories, such as market shares, survey results, or budget allocations.
For example, a pie chart is a good option to represent the time we spend on different daily activities. We can show the share of each activity in a day, such as sleeping, eating, studying, and working out.
Pie chart with pie()
We use the pie() built-in function to create pie charts in R. It takes numerical data and labels as input. We can use vectors to provide the data in pie()
pie(<data>, labels = c(<'label1'>,<'label2'>,...)
Here is a simple pie chart showing the monthly sale volumes of different products in a store.
- Line 2: We create a custom data container representing the sales of the store.
- Line 3: We create a container for the category names.
- Line 4: We use the containers in the
pie()function to generate the visualization.
Please notice that the pie() function assigns a distinct ...