Two-dimensional pie chart
The code is as follows:
#绘制2维饼图
X=read.delim ("C:/users/a/desktop/sample.txt", Header=false) #读入文本数据
names (x) =c ("word", "count") # Add Header
x=transform (x, Pct=round (X$count/sum (x$count) *100)) #数据框增加百分比列
Y=x[order (x[,2],decreasing=t),] #排序
Z=head (y,n=10) #抽取前10行
percent <-paste (z$pct, "%", sep= ") #add% to labels Lbls <-paste
(Z$word, Percent,sep= "\ n") #换行
Pie (z$pct,labels=lbls,col=rainbow length (lbls), main= "Pie Chart of Word")
3D Pie Chart
Following the previous data, the code to draw the R language to draw the 3D pie chart is as follows:
#3D饼图
Library ("Plotrix") Lp=pie3d (z$pct,radius=0.8,height=0.1,labels=lbls,explode=0.1,main= "3D pie DEMO")
#调整标签位置 (not good)
lp[1] <-0.05
lp[3] <-3.2 pie3d
(Z$pct,radius=0.8,height=0.1,labels=lbls, labelpos=lp,explode=0.1,main= "3D pie DEMO")
This article from the "Drip accumulation" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1640879