简体   繁体   English

如何制作百分比堆积条形图; 发生错误

[英]How to produce a percent stacked bar chart; error occuring

I have been trying to create a percent stacked bar chart using this code.我一直在尝试使用此代码创建百分比堆积条形图。 A data frame has already been created to have rows with only the conditions (stated in the code)已经创建了一个数据框以包含仅包含条件的行(在代码中说明)

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)

have also tried也试过

condition <- rep(c("At risk fo becoming threatened" , "Data deficient" , "Not threatened", "Threatened") , 5); value <- abs(rnorm(20 , 20 , 12))

error produced: arguments imply differing number of rows: 20, 15产生的错误:参数暗示不同的行数:20、15

However, this is the error that keeps on occurring, I have tried changing the "value" numbers但是,这是不断发生的错误,我尝试更改“值”数字

Error in data.frame(stacked_prep, condition, value) : arguments imply differing number of rows: 20, 16, 15 data.frame 中的错误(stacked_prep,条件,值):参数暗示不同的行数:20、16、15

Any help would be great任何帮助都会很棒

The length of each vector is different so you see this error.每个向量的长度不同,因此您会看到此错误。 You can use this codes to make data frame您可以使用此代码制作数据框

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM