简体   繁体   中英

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

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

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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