text: user3332: 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 ? 
  
  user3541: I have noticed a few errors:
  1) You define a bunch of variables (Species, Class, ...) but then instead of creating your data frame data with these you create it by reading from text. I don't think this is good practice, you should do so like in your example code.
  2) With the way you define, your data frame does not contain columns like Class or Species but columns V1 to V5, you should use argument header = TRUE in your read.table() call.
  3) Even when you read your data as in step 2, you would need to transform your data table into "long format", please see below.
  4) In your ggplot() call, you assign 7 to your y aesthetic, this does not make sense. You should either provide a vector of length equal to your other aesthetics (x and fill) or better a column name of values of interest.
  # This is your code minus the redundant variables that you have created but are
  # not used
  
  library(tidyr)
  library(ggplot2)
  
  # Pay attention to the header argument
  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",
    header = TRUE
  )
  
  # data in wide format
  > data
        Class Cames1 Came2 Cams3 cams4
  1       EVV   2194  5435  2706  2902
  2      MaLR    503   108   184   231
  3       psy    284   187   413   295
  4     Nargo    274  1977   413  2195
  5       Pao     66    29    78    97
  6   Unknown    286   283   273   377
  7 Undefined     76    77    80    95
  
  # Making the data wider: Keeping Class column as it is but condensing the data
  # within the rest of the columns into two newly created columns, Species_ and
  # Value_
  
  data_long <- gather(data,
                      key = "Species_",
                      value = "Value_",
                      -Class)
  
  # First few rows of your data in long format
  > head(data_long)
      Class Species_ Value_
  1     EVV   Cames1   2194
  2    MaLR   Cames1    503
  3     psy   Cames1    284
  4   Nargo   Cames1    274
  5     Pao   Cames1     66
  6 Unknown   Cames1    286
  
  # x and y aesthetics are the newly created columns Species_ and Value_
  ggplot(data_long, aes(fill=Class, y=Value_, x=Species_)) + geom_bar(position="dodge", stat="identity")
  
  
  
original_text: 3332: <p>I’m trying to create a Group Chart like this:
  <a href="https://i.stack.imgur.com/oVbX3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oVbX3.png" alt="aim somthing similar to this chart"></a></p>
  
  <p>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</p>
  
  <p>Here’s example provided online:</p>
  
  <pre><code>  library(ggplot2)
  
      # create a dataset
      specie &lt;- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3) )
      condition &lt;- rep(c("normal" , "stress" , "Nitrogen") , 4)
      value &lt;- abs(rnorm(12 , 0 , 15))
      data &lt;- data.frame(specie,condition,value) 
      # Grouped
      ggplot(data, aes(fill=condition, y=value, x=specie)) + 
          geom_bar(position="dodge", stat="identity")
  
  
  
  ------------------------------------------
      #Here’s code:
  
  
      &gt; Species &lt;- c(rep("Cames1" , 5) , rep("Came2" , 5) , rep("Cams3" , 5) , rep("cams4" , 5) )
      &gt; Class &lt;- rep(c("EVV" , "MaLR" , "psy" , "Nargo" , "Pao" , "Unknown" , "Undefiend") , 8)
      &gt; value &lt;- abs(rnorm(20 , 0 , 15 ))
      data &lt;- 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")
     &gt; 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
  </code></pre>
  
  <p>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 ? </p>
   3541: <p>I have noticed a few errors:</p>
  
  <p>1) You define a bunch of variables (Species, Class, ...) but then instead of creating your data frame data with these you create it by reading from text. I don't think this is good practice, you should do so like in your example code.</p>
  
  <p>2) With the way you define, your data frame does not contain columns like Class or Species but columns V1 to V5, you should use argument <code>header = TRUE</code> in your <code>read.table()</code> call.</p>
  
  <p>3) Even when you read your data as in step 2, you would need to transform your data table into "long format", please see below.</p>
  
  <p>4) In your <code>ggplot()</code> call, you assign 7 to your y aesthetic, this does not make sense. You should either provide a vector of length equal to your other aesthetics (x and fill) or better a column name of values of interest.</p>
  
  <pre><code># This is your code minus the redundant variables that you have created but are
  # not used
  
  library(tidyr)
  library(ggplot2)
  
  # Pay attention to the header argument
  data &lt;- 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",
    header = TRUE
  )
  
  # data in wide format
  &gt; data
        Class Cames1 Came2 Cams3 cams4
  1       EVV   2194  5435  2706  2902
  2      MaLR    503   108   184   231
  3       psy    284   187   413   295
  4     Nargo    274  1977   413  2195
  5       Pao     66    29    78    97
  6   Unknown    286   283   273   377
  7 Undefined     76    77    80    95
  
  # Making the data wider: Keeping Class column as it is but condensing the data
  # within the rest of the columns into two newly created columns, Species_ and
  # Value_
  
  data_long &lt;- gather(data,
                      key = "Species_",
                      value = "Value_",
                      -Class)
  
  # First few rows of your data in long format
  &gt; head(data_long)
      Class Species_ Value_
  1     EVV   Cames1   2194
  2    MaLR   Cames1    503
  3     psy   Cames1    284
  4   Nargo   Cames1    274
  5     Pao   Cames1     66
  6 Unknown   Cames1    286
  
  # x and y aesthetics are the newly created columns Species_ and Value_
  ggplot(data_long, aes(fill=Class, y=Value_, x=Species_)) + geom_bar(position="dodge", stat="identity")
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JXyOh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JXyOh.png" alt="enter image description here"></a></p>
  