Creating stacked bar graph with 32 columns and 61 rows

Hello!

This is my first time working with RStudio and I'm trying to make a bar graph of 32 different samples and 61 data points of different microbe percentages stacked.

I'm having trouble finding a tutorial that can help me graph the 32 samples with the stacked percentages of the microbes. Any help or direction would be greatly appreciated!

-Science Panda

Reshape first, using tidyr::gather.

Something like:

library(tidyverse)
my_data <- read.csv(.......)
my_data2 <- gather(my_data, microbe, count, -S1)

ggplot(my_data2, aes(S1, count, fill = microbe)) +
  geom_bar(aes(y = stat(prop))

Or perhaps it's the other way around:

my_data3 <- gather(my_data, sample, count, -S1)

ggplot(my_data3, aes(sample, count, fill = S1)) +
  geom_bar(aes(y = stat(prop))

I can't test, because I can't read in data from an image!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.