R语言基础绘图——饼图

R语言基础绘图——饼图

采用pie()绘制饼图
基本形式:
pie(x, labels = names(x), radius = ,main=" ", col = , clockwise = FALSE, density = , angle = , lty = , border = , edges = , …)

参数
x:表示一个非负的数值向量,表示每个扇形的面积。
labels:代表各扇形面积标签的字符型向量。
radius:表示饼图的圆的半径,特别是在字符标签过长的情况尤其适用。
main:用来表示图标的标题的。
col:表示每个扇形的颜色表示每个扇形的颜色
clockwise:一个逻辑值,TRUE顺时针做出分割,FALSE逆时针做出分割(默认)
density:底纹的密度。默认值为NULL。
angle:设置底纹的斜率
lty:设置边线类型
border:设置边线颜色
edges:设置多边形的边数(圆的轮廓是具有很多边的多边形近似)。


简单饼图
x <- c(50,100,80,130,150)
label <- c("黑龙江","北京", "山东", "广州", "浙江")
pie(x, labels = label)

attachments-2017-08-XWOthkrc598a64834cfe细化:
pie(x, labels = label,main="饼图",radius =0.8,col =c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"),clockwise = TRUE)
attachments-2017-08-2qR6jWeA598a64a4ecf4pie(x, labels = label,main="饼图",radius =0.8,col =c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"),clockwise = TRUE,density =100,angle =45,edges = 3)

attachments-2017-08-Q2W3V1Xy598a64c1d5d8

标注各扇形的百分比以及添加图表图例
percent<-round(100*x/sum(x),2)   #保留两位小数
percent <-paste(percent, "%", sep = "")  #将不同数据类型放在一起
pie(x, labels = percent,main="饼图",radius =0.8,col =c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"),clockwise = TRUE)
legend("topright",label, cex=0.8, fill=c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"))
attachments-2017-08-bwSlqzDx598a64df9b60手动设置图例位置(选定位置双击鼠标):locator()参数
pie(x, labels = percent,main="饼图",radius =0.8,col =c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"),clockwise = TRUE)
legend(locator(1),,label, cex=0.8, fill=c("cadetblue","cadetblue1","cadetblue2","cadetblue3","cadetblue4"))attachments-2017-08-HqOFaK6j598a64f68e2f

采用pie3D()绘制3D饼图:
install.packages("plotrix")
library(plotrix)

基本形式:
pie3D(x, labels=  , main=" ", explode= , radius= , height= ,col= ,...)

参数:
labels:各个“块”的标签
main:饼图主标题
explode:各个“块”之间的间隔,默认值为0
radius:整个“饼”的大小,默认值为1,0~1为缩小
height:饼块的高度,默认值为0.1


绘制简单3D饼图:
pie3D(x,labels=label)

attachments-2017-08-s0Bb8bk1598a6516cc35美化:
pie3D(x,labels=label,explode=0.1, radius=0.9 , height=0.07,col=c("#f20c00","#f05654","#ffb3a7","#8c4356","#ff2d51"))
attachments-2017-08-T5sKfvGq598a652b2e13
标注各扇形百分比及添加图例:
percent<-round(100*x/sum(x),2)   #保留两位小数
percent <-paste(percent, "%", sep = "")  #将不同数据类型放在一起
pie3D(x,labels=percent,explode=0.1, radius=0.9 , height=0.07,col=c("#f20c00","#f05654","#ffb3a7","#8c4356","#ff2d51"))
legend("topright",label, cex=0.8, fill=c("#f20c00","#f05654","#ffb3a7","#8c4356","#ff2d51"))

attachments-2017-08-FasMc55Z598a6544499c







  • 发表于 2017-08-09 09:29
  • 阅读 ( 17142 )
  • 分类:编程语言

0 条评论

请先 登录 后评论
不写代码的码农
爽儿

学生

25 篇文章

作家榜 »

  1. 祝让飞 118 文章
  2. 柚子 91 文章
  3. 刘永鑫 64 文章
  4. admin 57 文章
  5. 生信分析流 55 文章
  6. SXR 44 文章
  7. 张海伦 31 文章
  8. 爽儿 25 文章