## 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
,但是以某种方式我没有得到线。请让我知道某些功能是否可以在这里工作或在pareto中不允许使用
abline
吗? 最佳答案
视差图表和条形图pareto.chart()
基于barplot()
,因此,只要您知道如何将abline()
添加到barplot()
,您就知道如何使用pareto.chart()
。为了说明他们之间的关系,请考虑以下因素:
## 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()
:pareto.chart(defect, ylab = "Error frequency")
abline(v = x, col = 2) ## red
每0.1分位数添加
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")
作为示范,我使用
set.seed(0); Product <- rbinom(100, 20, 0.3)
关于r - 如何将abline()添加到pareto.chart()/barplot()?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37915779/