pie chart ये user के द्वारा दिए गए vector के मुताबिक circle के slices का वर्णन करता है और हर slice को label दिया जाता है |
pie chart के लिए pie() function का इस्तेमाल किया जाता है | pie() function पर दिए हुए vectors के elements positive होना जरुरी होता है |
Syntax for pie() Function in R
pie(vector, labels, main, col, border, lty, clockwise)
Parameter for pie() Function in R
vector : vector. यहाँ पर vector दिया जाता है और उसपर numeric elements दिए जाते है |
labels : vector. यहाँ पर circle के किये हुए विभागों को नाम दिए जाते है |
main : string. यहाँ पर pie chart का title दिया जाता है |
col : vector. यहाँ पर colors के नाम दिए जाते है |
border : string. यहाँ पर bordre color name दिया जाता है |
lty : numeric. यहाँ पर pie chart के line का type number में दिया जाता है |
clockwise : अगर TRUE होता है तो clockwise slices किये जाते है और अगर FALSE होता है तो anti-clockwise slices किये जाते है |
Simple Example for pie() Function in R
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') pie(val, labels)
1.png)
Add Title to a Pie Chart in R
Example पर pie chart को title दिया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') pie(val, labels, main = "Electronics")
2.png)
Fill own colors in circle's slices in R
Example पर अपने खुद के colors से circle के slices को fill किया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie(val, labels, main = "Electronics", col = colors)
3.png)
Add Label as Percentages on Slices in R
Example पर label को percentages के रूप में दिखाया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') per = round(100*val/sum(val), 1) pie(val, labels = per, main = "Electronics", col = colors)
4.png)
Change Pie Chart Line Type in R
Example पर line type को change किया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie(val, labels, main = "Electronics", col = colors, lty = 2)
5.png)
Change Pie Chart Border Color in R
Example पर pie chart की border को set किया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie(val, labels, main = "Electronics", col = colors, border = 'red')
6.png)
Set Circle's slices clockwise in R
Example पर clockwise; circle के slices को set किया गया है |
Source Code :Output :val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie(val, labels, main = "Electronics", col = colors, border = 'red', clockwise = TRUE)
7.png)
Create 3D pie chart in R
Example पर 3D pie chart को display किया गया है |
pie3D() Function के लिए plotrix इस library को import किया जाता है | इसे पहले R पर install किया जाता है |
For plotrix package installation : RGui > Packages > Install package(s)... > Select Plotrix and wait for some seconds
Output :library(plotrix) val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie3D(val, labels = labels, main = "Electronics")
8.png)
Explode 3D pie chart using explode() in R
Example पर pie chart में circle के slices को explode किया गया है |
Source Code :Output :library(plotrix) val = c(15,20,30,5) labels = c('TV','Refrigerators','Cooler','AC') colors = c('red', 'green', 'blue', 'yellow') pie3D(val, labels = labels, main = "Electronics", explode = 0.2)
9.png)
R Pie Chart पर legend को describe करने के लिए यहाँ पर click करे |