R Pie Chart

The pie chart is a circular statical graph, which represent the values in slices. In R, we can generate pie chart using pie() function.

Syntax of Pie Plots

pie(x, labels, radius, main, col, clockwise) 

x - x is the data to plot on a graph.
labels - labels specify the description of slices.
col - col attribute sets the color of slices.
main - main attribute is to give a title to the graph.
clockwise - clockwise specifies whether the slices are drawn clockwise or anticlockwise.

Example of R Pie Chart

In the example below, we generate a pie chart with two vectors and also set colors.

people <- c(24, 32, 34, 30, 40)
food <- c('Sandwich','Pizza','Donuts','Noodles','Burger')
pie(people, food, col=c('red','yellow','purple','blue','green'))

The above code generates this graph.

R Pie Charts