R Func Pie
# R pie() Function - Drawing Pie Charts
[ R Language Examples](#)
The R pie() function is used to draw pie charts, showing the proportion of each part in the whole.
Pie charts are suitable for displaying the proportion relationship of no more than 5-6 categories.
The pie() function syntax is as follows:
pie(x, labels = names(x), radius = 0.8, main = "", col = NULL, clockwise = FALSE)
**Parameter Description:**
* **x** Numeric vector of each part.
* **labels** Labels for each part.
* **radius** Pie chart radius (0-1), default 0.8.
## Example
# Market share data
market_share <-c(35, 28, 20, 12, 5)
names(market_share)<-c("Company A", "Company B", "Company C",
"Company D", "Other")
# Calculate percentage
pct <-round(market_share /sum(market_share)*100, 1)
labels<-paste(names(market_share), "n", pct, "%", sep ="")
# Draw pie chart
pie(market_share,
labels=labels,
main ="Market Share Distribution",
col=c("steelblue", "coral", "seagreen",
"gold", "gray"))
Executing the above code will display a pie chart of each company's market share with percentage labels.
[ R Language Examples](#)
YouTip