R语言—帕累托图

浏览: 1705

本文的主要目的有两个一个是学习如何在R中绘制帕累托图,另一个是如何绘制双坐标图,其中前三个例子是用绘制双坐标的方式绘制帕累托图的,其余为直接生成的帕累托图。

@ 不用包

par(mar=c(5,5,4,5)+0.1)
bar <- barplot(absolute,ylab="总数",col="skyblue",col.axis="skyblue",col.lab="skyblue")
mtext(LETTERS[1:8],side=1,line=1,at=bar,col="black")
#mtext(" ",side=1,line=3,col="black")
par(new=T)
plot(bar,cum_per,axes=F,xlab="",ylab="",col="red",type="b")
axis(4,col="red",col.ticks="red",col.axis="red")
mtext("累计百分比%",side=4,line=3,col="red")
title(main = '帕累托图')

Clipboard Image.png

@ plotix


library(plotrix)
type <- 1:8
absolute <- c(15,18,23,28,18,9,7,13)
cum_per <- cumsum(absolute)/sum(absolute)
twoord.plot(lx = type, ly = absolute, rx = type, ry = cum_per, type=c('bar','l'),
            lcol = 'skyblue', rcol = 'red', ylab = '总数',
            rylab = '累计百分比%', main = '帕累托图', xtickpos=type, 
            xticklab = LETTERS[1:8])

Clipboard Image.png
@ TeachingDemos包

par(mar=c(5,5,4,5)+0.1)
library(TeachingDemos)
bar <- barplot(absolute,ylab="总数",col="skyblue",col.axis="skyblue",col.lab="skyblue")
updateusr(1:2,range(min(absolute),max(absolute)),1:2,range(min(cum_per),
                                                          max(cum_per)))
lines(bar,cum_per,type="b",col="red")
axis(4,col="red",col.ticks="red",col.axis="red")
mtext("累计百分比%",side=4,line=3,col="red")
mtext(LETTERS[1:8],side=1,line=1,at=bar,col="black")
title(main = '帕累托图')

Clipboard Image.png
@ qcc包

library(qcc)
absolute <- c(15,18,23,28,18,9,7,13)
names(absolute) <- LETTERS[1:8]
pareto.chart(absolute, ylab = "总数",ylab2 = "累计百分比%",
             main='帕累托图')

Clipboard Image.png
@ qualityTools包

library(qualityTools)
#artifical defects dataset
absolute <- c(15,18,23,28,18,9,7,13)
names(absolute) <- LETTERS[1:8]
cum_per <- cumsum(absolute)/sum(absolute)
paretoChart(absolute,cum_per,main='帕累托图',ylab = "总数")

Clipboard Image.png
@ qicharts包

library(qicharts)
x <- rep(LETTERS[1:9], c(256, 128, 64, 32, 16, 8, 4, 2, 1))
paretochart(x)

Clipboard Image.png

@ fdth

library(fdth)
x <- rep(LETTERS[1:9], c(256, 128, 64, 32, 16, 8, 4, 2, 1))
dc <- fdt_cat(x)
plot(dc,type='pa',col=c('skyblue','red'))  

Clipboard Image.png


文章选摘:EasyCharts公众号


推荐 0
本文由 R语言中文社区 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册