r语言 - 如何制作百分比堆叠条形图;错误发生



我一直在尝试使用此代码创建百分比堆叠条形图。已经创建了一个数据帧,它的行只包含条件(在代码中声明)

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, condition, value)出错:参数表示不同的行数: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)

相关内容

最新更新