![](/img/trans.png)
[英]How to add percent of each category to stacked bar chart (ggplot2) (for a “non-percent” stacked chart)
[英]How to produce a percent stacked bar chart; error occuring
我一直在嘗試使用此代碼創建百分比堆積條形圖。 已經創建了一個數據框以包含僅包含條件的行(在代碼中說明)
stacked_prep<- c(rep("Sharks, rays, and chimaeras" , 5) , rep("Marine mammals" , 5) , rep("Seabirds" , 5) , rep("Shorebirds" , 5))
condition <- rep(c("At risk fo becoming threatened" , "Data deficient" , "Not threatened", "Threatened") , 4)
value <- abs(rnorm(15 , 20 , 12))
data <- data.frame(stacked_prep,condition,value)
也試過
condition <- rep(c("At risk fo becoming threatened" , "Data deficient" , "Not threatened", "Threatened") , 5); value <- abs(rnorm(20 , 20 , 12))
產生的錯誤:參數暗示不同的行數:20、15
但是,這是不斷發生的錯誤,我嘗試更改“值”數字
data.frame 中的錯誤(stacked_prep,條件,值):參數暗示不同的行數:20、16、15
任何幫助都會很棒
每個向量的長度不同,因此您會看到此錯誤。 您可以使用此代碼制作數據框
stacked_prep<- c(rep("Sharks, rays, and chimaeras" , 5) , rep("Marine mammals" , 5) , rep("Seabirds" , 5) , rep("Shorebirds" , 5))
condition <- rep(c("At risk fo becoming threatened" , "Data deficient" , "Not threatened", "Threatened") , 5)
value <- abs(rnorm(20 , 20 , 12))
data <- data.frame(stacked_prep,condition,value)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.