rhelp
rhelp

Reputation: 1

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

Upvotes: 0

Views: 29

Answers (1)

Ameneh Abyar
Ameneh Abyar

Reputation: 35

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)

Upvotes: 1

Related Questions