R Pie Charts

R programming language provides many numbers of libraries to create charts and graphs. A pie-chart is a representation of data as slices of a circle with different colors representing counts or proportions. Each slice is labeled and the numbers corresponding to each slice is also represented in the chart.

In R, pie() function is used to create a pie chart. This function takes positive numbers as a vector input. The additional parameters are used to control colors, labels, title, etc.

Syntax:

Here,

x is a vector of numeric values used in the pie chart.

lables is the description of the slices.

radius is the radius of the circle of the pie chart (Value between -1 and +1)

main is the title of the chart

col represents the color.

clockwise is a logical value represents if the slices are drawn clockwise or anti clockwise.

Example:

Let’s create a simple pie chart using the input vector and labels. The following script will create and save the pie chart in the current R working directory:

Output:

pie chart in the current R

Pie Chart Title and Color

We can add more parameters to the pie function. Here, we will use main and col parameter.

Example:

Output:

city pie function

Slice Percentage and Chart Legend

We can also add slice percentage and a chart legend by creating additional chart variables.

Example:

Output:

Slice Percentage and Chart Legend

3D pie Chart

R provides additional package to draw a pie chart in 3 dimensions. The name of the package is plotrix. This package has a function pie3D() that is used for 3D design.

Example:

Output:

3D pie Chart