当前位置:天才代写 > tutorial > R语言教程 > R语言教程之如何生成饼状图

R语言教程之如何生成饼状图

2018-05-09 08:00 星期三 所属: R语言教程 浏览:1802

R文档不建议使用饼图,它们的功能有限。作者在饼图上推荐条形图点图,因为人们能够比卷更准确地判断长度。饼图由函数pie(,labels =)创建,其中x是一个非负数字向量,指示每个切片的面积,labels =记录切片名称的字符向量。

简单的饼图

# Simple Pie Chart
slices <- c(10, 12,4, 16, 8)
lbls <- c("US", "UK", "Australia", "Germany", "France")
pie(slices, labels = lbls, main="Pie Chart of Countries")

简单的饼图 点击查看

带注释百分比的饼图

# Pie Chart with Percentages
slices <- c(10, 12, 4, 16, 8) 
lbls <- c("US", "UK", "Australia", "Germany", "France")
pct <- round(slices/sum(slices)*100)
lbls <- paste(lbls, pct) # add percents to labels 
lbls <- paste(lbls,"%",sep="") # ad % to labels 
pie(slices,labels = lbls, col=rainbow(length(lbls)),
   main="Pie Chart of Countries")

花哨的饼图 点击查看

3D饼图

plotrix软件包中pie3D()函数提供了3D爆炸饼图。

# 3D Exploded Pie Chart
library(plotrix)
slices <- c(10, 12, 4, 16, 8) 
lbls <- c("US", "UK", "Australia", "Germany", "France")
pie3D(slices,labels=lbls,explode=0.1,
   main="Pie Chart of Countries ")

3D饼图 点击查看

从数据框中创建带注释的派

# Pie Chart from data frame with Appended Sample Sizes
mytable <- table(iris$Species)
lbls <- paste(names(mytable), "\n", mytable, sep="")
pie(mytable, labels = lbls, 
   main="Pie Chart of Species\n (with sample sizes)")

数据框中的饼图 点击查看

 

    关键字:

天才代写-代写联系方式