Relative abundance_Out of 100%

Hello everyone,

I have one question regarding the relative frequency plot. I am trying to perform a stacked plot for my microbiome data, but in y axis (relative frequencies) I get much more than 100. The sum of each bacteria (relative frequency) is 100 but I don't know why it goes way higher than 100 in the plot. I have read other posts but I couldn't figured it out. I really appreciate if you can help me out, please.

The first 10 rows of the data are the following:

1

The codes that I am using are:

library(tidyverse)
library(readxl)
library(glue)
library(ggtext)
library(patchwork)
library(reshape2)
library(ggtext)

pc = read.csv("L2_16S_R2.csv", header = TRUE)
#convert data frame from a "wide" format to a "long" format
pcm = melt(pc, id = c("Vineyard"))
View(pcm)
str(pcm)
pcm %>%
  group_by(Vineyard, variable) %>%
  summarize(value = sum(value), .groups="drop") %>%
  group_by(Vineyard, variable) %>%
  summarize(mean_value = mean(value), .groups="drop") %>%
  mutate(variable=str_replace(variable,
                           "(.*)_unclassified", "Unclassified *\\1*"),
         variable = str_replace(variable,
                             "^(\\S*)$", "*\\1*")) %>% 
  ggplot(aes(x=Vineyard, y=mean_value, fill= variable)) +
  geom_col() +
  labs(x = NULL,
       y = "Mean relative abundance (%)") + 
  theme_classic() +
  theme(axis.text.x = element_markdown(),
        legend.text = element_markdown())

  

And the plot is:

Thank you

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Thank you for the link.
I try to follow based on the guideline.

head(pc)
Vineyard Bacteria_unclassified Acidobacteria Actinobacteria Bacteroidetes
1   MOL_PI              5.081867      4.644098       4.453394      3.192632
2   MOL_PI              2.494538      3.162059       1.746438      1.328089
3   MOL_PI              1.930898      2.045947       2.262010      2.412740
4   MOL_PI              2.374574      3.004277       1.625022      1.920817
5   MOL_PI              1.515035      2.045939       2.150442      3.603883
6   MOL_PI              1.828937      1.717337       1.654520      3.223426
  Chlamydiae Chloroflexi Fibrobacteres Firmicutes Gemmatimonadetes Planctomycetes
1   2.796760    2.328822      1.969988   1.969880         1.949909       0.949891
2   1.531040    1.995751      1.503860   2.151369         1.887314       2.536497
3   1.541752    1.155944      2.039573   1.313711         2.166829       2.271800
4   1.404445    1.529284      1.852650   1.399901         2.892016       1.909484
5   1.342512    1.371413      1.141715   1.205557         1.287703       2.616590
6   1.355212    1.049989      2.117746   1.190188         1.566800       1.943042
  Proteobacteria Verrucomicrobia
1       0.762190        0.000000
2       2.079625        1.696870
3       2.197808        2.155778
4       2.037909        2.108571
5       2.014559        2.521974
6       2.068532        2.519107

#convert data frame from a "wide" format to a "long" format
pcm = melt(pc, id = c("Vineyard"))

 Vineyard              variable    value
1   MOL_PI Bacteria_unclassified 5.081867
2   MOL_PI Bacteria_unclassified 2.494538
3   MOL_PI Bacteria_unclassified 1.930898
4   MOL_PI Bacteria_unclassified 2.374574
5   MOL_PI Bacteria_unclassified 1.515035
6   MOL_PI Bacteria_unclassified 1.828937

The code that I am using for the plot is:

pcm %>%
  group_by(Vineyard, variable) %>%
  summarize(value = sum(value), .groups="drop") %>%
  group_by(Vineyard, variable) %>%
  summarize(mean_value = mean(value), .groups="drop") %>%
  mutate(variable=str_replace(variable,
                           "(.*)_unclassified", "Unclassified *\\1*"),
         variable = str_replace(variable,
                             "^(\\S*)$", "*\\1*")) %>% 
  ggplot(aes(x=Vineyard, y=mean_value, fill= variable)) +
  geom_col() +
  labs(x = NULL,
       y = "Mean relative abundance (%)") + 
  theme_classic() +
  theme(axis.text.x = element_markdown(),
        legend.text = element_markdown())