ggplot中的堆积条形图来自此表

时间:2017-10-16 18:20:04

标签: r ggplot2

所以我有一个非常复杂的(至少对我来说是哈哈)ggplot,我试图从这个数据创建。

Issue = c("Difficulty receiving products in general", 
"Supplier compliance issues", "Supplier fraud, waste, or abuse", 
"Difficulty receiving products in general", "Difficulty receiving products in general", 
"Supplier fraud, waste, or abuse", "Supplier service issues", 
"Problems repairing due to service issues ", "Problems repairing due to service issues ", 
"Other", "Billing, coverage, coordination of benefits", "Problems repairing due to service issues ", 
"Difficulty receiving products in general", "Difficulty receiving products in general", 
"Low quantity/quality", "Difficulty receiving products in general", 
"Difficulty receiving products in general", "Supplier service issues", 
"Problems repairing due to service issues ", "Problems repairing due to service issues ", 
"Problems repairing due to service issues ", "Problems repairing due to lack of inventory ", 
"Supplier service issues", "Difficulty receiving products in general", 
"Supplier service issues")

Resolution = c("Current supplier resolved the issue", 
"Current supplier resolved the issue", "Current supplier resolved the issue", 
"Supplier educated about inquiry\n", "Beneficiary educated about inquiry ", 
"Supplier educated about inquiry\n", "Beneficiary educated about DMEPOS\n", 
"Beneficiary educated about inquiry ", "Beneficiary educated about inquiry ", 
"Beneficiary educated about inquiry ", "Beneficiary educated about suppliers", 
"The case unresolved ", "The case unresolved ", "Beneficiary educated about DMEPOS\n", 
"Current supplier resolved the issue", "Current supplier resolved the issue", 
"Beneficiary educated about DMEPOS\n", "Beneficiary educated about suppliers", 
"New supplier found ", "Beneficiary educated about suppliers", 
"Supplier educated about inquiry\n", "New supplier found ", 
"New supplier found ", "Beneficiary educated about DMEPOS\n", 
"The case unresolved ")

df <- data.frame(Issue,Resolution)
crosstable<- table(df$Issue,df$Resolution)

我想创建一个堆积条ggplot,它在x轴上有问题,然后在y轴上计数,但也显示每个问题如何按分辨率细分。这在excel中很容易做到,但由于我在R中制作其他图形,我希望保持美学一致。

1 个答案:

答案 0 :(得分:1)

尝试:

ggplot(df, aes(Issue, fill = Resolution)) + geom_bar()

如果这不是订单,只需切换问题和解决方案的位置。