R Pie Charts
Pie charts in R are used to represent parts of a whole. The pie()
function is used to create pie charts with labels and colors.
Key Topics
Pie Chart Example
# Creating a pie chart
slices <- c(10, 20, 30, 40)
labels <- c("A", "B", "C", "D")
pie(slices, labels = labels, main = "Pie Chart Example")
Output:
A pie chart with slices labeled A, B, C, and D, representing the specified values.
Code Explanation: The pie()
function creates a pie chart with the slices
vector and labels for each slice.
Customizing Pie Chart
You can customize pie charts by adding colors and adjusting the label positions.
# Customizing the pie chart
colors <- c("red", "blue", "green", "yellow")
pie(slices, labels = labels, col = colors, main = "Customized Pie Chart")
Output:
A pie chart with slices in different colors: red, blue, green, and yellow.
Code Explanation: The col
parameter is used to specify colors for each slice of the pie chart.
Key Takeaways
- Use the
pie()
function to create pie charts in R. - Labels and colors can be customized to enhance visual appeal.
- Pie charts are useful for displaying parts of a whole.