本文的主要目的有两个一个是学习如何在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 = '帕累托图')
@ 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])
@ 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 = '帕累托图')
@ qcc包
library(qcc) absolute <- c(15,18,23,28,18,9,7,13) names(absolute) <- LETTERS[1:8] pareto.chart(absolute, ylab = "总数",ylab2 = "累计百分比%", main='帕累托图')
@ 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 = "总数")
@ qicharts包
library(qicharts) x <- rep(LETTERS[1:9], c(256, 128, 64, 32, 16, 8, 4, 2, 1)) paretochart(x)
@ 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'))
文章选摘:EasyCharts公众号
|
请发表评论