# How to create pie chart in base R with labels?

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

A pie chart is a circular representation of data which is created for either nominal data or ordinal data. The slices in the pie chart depends on the magnitude of the data values. If we want to create a pie chart in base R with then pie function can be used along with labels argument.

Check out the Examples given below to understand how it can be done.

## Example

To create a pie chart in base R with labels, use the following command −

x<-sample(1:20,8)
pie(x)

## Output

If you execute the above given command, it generates the following Output −

To create a pie chart in base R with labels add the following code to the above snippet −

x<-sample(1:20,8)
pie(x,labels=LETTERS[1:8])

## Output

If you execute all the above given snippets as a single program, it generates the following Output −

To create a pie chart in base R with labels add the following code to the above snippet −

x<-sample(1:20,8)
pie(x,labels=c(1,2,5,4,3,7,8,6))

## Output

If you execute all the above given snippets as a single program, it generates the following Output −

Updated on 10-Nov-2021 08:07:16

Advertisements