R Pie Chart

Create's a pie chart using the pie() function.
Syntax pie(values, labels = categories)


# Example data
categories <- c("Category A", "Category B", "Category C", "Category D")
values <- c(30, 20, 15, 35)

# Create a pie chart
pie(values, labels = categories, main = "Pie Chart")

Use of attributes

We can use attributes to make a difference.
  1. main - The main title of the plot.
  2. col - Colors for each sector.
  3. border - Color of the border of each sector.
  4. explode - A vector indicating how much each slice should be offset from the center.
  5. init.angle - Specifies the initial angle of the first slice in a pie chart.


# Customized pie chart
colors <- c("red", "green", "blue", "yellow")
border_color <- "black"
explode <- c(0.1, 0, 0, 0.2)

pie(values, labels = categories, col = colors, init.angle = 90 border = border_color, explode = explode, main = "Customized Pie Chart")
legend("topright", colors, fill = colors)

Quick Recap - Topics Covered

R Pie Chart
Use of Attributes

Practice With Examples in Compilers

The Concepts and codes you leart practice in Compilers till you are confident of doing on your own. A Various methods of examples, concepts, codes availble in our websites. Don't know where to start Down some code examples are given for this page topic use the code and compiler.

Example js

Example 1 Example 2 Example 3 Example 4 Example 5