帕累託圖和柱狀圖中
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 and bar](https://i.stack.imgur.com/kbgZ2.jpg)
現在你可以看到吧一致。
酒吧在哪裏?
這是一個陷阱,pareto.chart()
不會返回這些酒吧的位置。此前我們已經保存在y
pareto.chart()
的結果,現在這都是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
通過這種方式,我們必須調用
x <- as.numeric(barplot(defect, plot = FALSE))
# > x
# [1] 0.7 1.9 3.1 4.3 5.5
現在,如果我們在這些位置做abline()
:爲了得到酒吧的位置barplot()
pareto.chart(defect, ylab = "Error frequency")
abline(v = x, col = 2) ## red
![abline](https://i.stack.imgur.com/yNBRw.jpg)
添加abline()/segments()
每0.1分位數
我會建議使用:
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)
![plot](https://i.stack.imgur.com/EDLdD.jpg)
剛剛加入這個或其他的例子,因爲這: abline(V = 1000,山口=「紫色」) –
對不起,我是新於R,但我想只要我的V = 1000它會告訴我一個垂直線。這不正確嗎?我也用排序的所有十個區間這樣v = seq(0,100,by = 25),但沒有解決。因此,以v = 1000爲例,看看這條線是否出現,但沒有任何信息 –
x的長度以百萬爲單位 –