0

我创建了一个帕累托图,如下图所示。

而不是“A”、“E24”等,我想为前 20% 添加标签“A”,为 20-50% 添加标签“B”,为 50-100% 添加标签“C”。有没有可能调整这个?

https://i.stack.imgur.com/VkPFw.png

https://i.stack.imgur.com/2pHYa.png

#Total quantities (selling units) requested of each SKU
SkuQuantities <- ddply(sales, .(Sku_id), summarize, Count=length(Order_qty), SumOrder_qty=sum(Order_qty))
SkuQuantities <- na.omit(SkuQuantities) # Remove NA
SkuQuantities <- arrange(SkuQuantities, SumOrder_qty, decreasing = TRUE) #Decreasing order
SkuQuantities['cum'] <- NA # Make new column 'cum'
SkuQuantities <- SkuQuantities %>% mutate(cum = cumsum(SumOrder_qty)/sum(SumOrder_qty)) # cumulative percentages
SkuQuantities['label'] <- NA

# Assign label to Sku's based on cumulative requests
for(i in 1:nrow(SkuQuantities)){
 if(SkuQuantities$cum[i] < 0.2){
    SkuQuantities$label[i] <- "A"}
 else if(SkuQuantities$cum[i] < 0.5){
    SkuQuantities$label[i] <- "B"}
 else{
    SkuQuantities$label[i] <- "C"}
}

write.xlsx(SkuQuantities, 'SkuQuantities.csv')

library(qcc)
SKUplot <- pareto.chart(SkuQuantities$SumOrder_qty)
SKUplot
4

0 回答 0