如何将abline()添加到pareto.chart()/ barplot()?

时间:2016-06-20 06:24:19

标签: r plot bar-chart

enter image description here

我正在使用这个作为pareto图表(库qcc):

## abcd is a data frame, and I am producing chart for column products
Product <- abcd$products
names(Product)<-abcd$customerid
pareto.chart(Product, ylab = "Number of Products", xlab="Customer", xaxt="n")
abline(v = 1000)

由于我的数据很大,我想在x轴的10%间隔之后添加abline,但不知怎的,我没有得到这些线。

如果某些功能可以在这里使用,或者{0}不允许在帕累托中使用,请告诉我?

1 个答案:

答案 0 :(得分:5)

帕累托图和条形图

git push origin master基于pareto.chart(),因此只要您知道如何将barplot()添加到abline(),就知道如何处理barplot()。为了证明他们之间的关系,请考虑以下事项:

pareto.chart()

pareto and bar

现在你可以看到这些酒吧重合。

酒吧在哪里?

## example from ?pareto.chart defect <- c(80, 27, 66, 94, 33) names(defect) <- c("price code", "schedule date", "supplier code", "contact num.", "part num.") y <- pareto.chart(defect, ylab = "Error frequency") barplot(0.2 * defect, add = TRUE, col = "grey") 没有返回那些酒吧的位置是一个陷阱。以前我们已将pareto.chart()的结果保存在pareto.chart()中,现在这已全部y了:

y

这就是所有要打印的内容:

> str(y)
num [1:5, 1:4] 94 80 66 33 27 94 174 240 273 300 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:5] "contact num." "price code" "supplier code" "part num." ...
  ..$ Pareto chart analysis for defect: chr [1:4] "Frequency" "Cum.Freq." "Percentage" "Cum.Percent."

通过这种方式,我们必须致电> y Pareto chart analysis for defect Frequency Cum.Freq. Percentage Cum.Percent. contact num. 94 94 31.33333 31.33333 price code 80 174 26.66667 58.00000 supplier code 66 240 22.00000 80.00000 part num. 33 273 11.00000 91.00000 schedule date 27 300 9.00000 100.00000 才能获得酒吧位置:

barplot()

现在,如果我们对这些职位进行x <- as.numeric(barplot(defect, plot = FALSE)) # > x # [1] 0.7 1.9 3.1 4.3 5.5

abline()

abline

每0.1分位数添加pareto.chart(defect, ylab = "Error frequency") abline(v = x, col = 2) ## red

我建议使用:

abline() / segments()

作为演示,我使用

x <- range(as.numeric(barplot(Product, plot = FALSE)))
x0 <- seq(x[1], x[2], length = 11)  ## 11 break points for 10 intervals
y <- pareto.chart(Product, ylab = "Number of Products", xlab="Customer", xaxt="n")[, 2]
y0 <- y[round(seq(from = 1, to = length(y), length = 11))]
## abline(v = v0, col = "purple")
segments(x0, rep(0, 11), x0, y0, col = "purple")

plot