Making multiple box plots with relative abundance in R
1
0
Entering edit mode
13 months ago
ohtang7 ▴ 40

I am creating a relative abundance boxplot comparing two groups (pet, stray) using eight genera. However, the resulting plot displays almost zero values on the y-axis and only one value on the x-axis. I aim to generate a boxplot comparing the relative abundance of eight genera across two groups (pet, stray). How can I modify my code to achieve this?

I suspect that one genus has a significantly different scale of relative abundance, potentially causing the issue with the y-axis. If transforming the y-axis is an effective solution, please suggest appropriate transformations for the relative abundance values with revised code.

my R code is

library(ggplot2)
data <- read.csv("relative abundance raw data (putative pathogen).csv")
p<-ggplot(data, aes(x="Genus", y="Relative_abundance", fill="Group")) +
geom_boxplot(position = position_dodge(width = 0.8), alpha = 0.8) +
labs(title = "Relative Abundance Comparison",
x = "Genus",
y = "Relative Abundance",
fill = "Group") +
theme_minimal() +
scale_fill_manual(values = c("stray" = "blue", "pet" = "red"))
p + geom_jitter(shape=16, position=position_jitter(0.2))

the result figure : enter image description here

my raw data format is : enter image description here

My raw data file can be downloaded here : https://drive.google.com/file/d/1Dxy2EqqgC2BQK6b92gRHSI5t7DtA29YA/view?usp=sharing

Thank you for your assistance !

R Boxplots • 938 views
ADD COMMENT
0
Entering edit mode
13 months ago

When you pass variables to aes you don't want to quote them.

ggplot(data, aes(x="Genus", y="Relative_abundance", fill="Group"))

should be

ggplot(data, aes(x=Genus, y=Relative_abundance, fill=Group))

Also with such small values you want to greatly reduce your y-axis jitter. Try something like like height=0.001 in geom_jitter first and increase as needed.

ADD COMMENT
0
Entering edit mode

enter image description here

Thank you dear !!!

I have one more question, the box doesn't show color as I intended... What should be chaged from the code ?

ADD REPLY
0
Entering edit mode

In scale_fill_manual you have e.g. "stray" but in your data it's "Stray". Just make sure the cases match.

ADD REPLY
0
Entering edit mode

Thank you!! I really appreciate your help.

ADD REPLY

Login before adding your answer.

Traffic: 1898 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6