I’m trying to create a Group Chart like this:
I have 7 classes for each of 4 species, not 5 like in the diagram. I want to build i diagram to show the distributions of the classes in each species
Here’s example provided online:
library(ggplot2)
# create a dataset
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
condition <- rep(c("normal" , "stress" , "Nitrogen") , 4)
value <- abs(rnorm(12 , 0 , 15))
data <- data.frame(specie,condition,value)
# Grouped
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="dodge", stat="identity")
------------------------------------------
#Here’s code:
> Species <- c(rep("Cames1" , 5) , rep("Came2" , 5) , rep("Cams3" , 5) , rep("cams4" , 5) )
> Class <- rep(c("EVV" , "MaLR" , "psy" , "Nargo" , "Pao" , "Unknown" , "Undefiend") , 8)
> value <- abs(rnorm(20 , 0 , 15 ))
data <- read.table(text="Class Cames1 Came2 Cams3 cams4
+ EVV 2194 5435 2706 2902
+ MaLR 503 108 184 231
+ psy 284 187 413 295
+ Nargo 274 1977 413 2195
+ Pao 66 29 78 97
+ Unknown 286 283 273 377
+ Undefined 76 77 80 95")
> ggplot(data, aes(fill=Class, y=7, x=Species)) + geom_bar(position="dodge", stat="identity")
Error: Aesthetics must be either length 1 or the same as the data (7): x, fill
i am able to build basics chart, but to group them all into one like the example provided challenging for me , could someone help out ?