Negative bacteria

Processing data

Gram_neg_SIR_diameter <- read.table("/Users/qcvp/R/Mẫu RIVS/báo20192020/negative.txt", sep = "\t", header = T)
names(Gram_neg_SIR_diameter)
##  [1] "Sample.ID" "NA."       "AN"        "AUG"       "ATM"       "FEP"      
##  [7] "FOX"       "CIP"       "SXT"       "ETP"       "FF"        "CN"       
## [13] "IPM"       "LEV"       "PIP"       "PTZ"       "TIC"       "TCC"      
## [19] "TOB"       "Taxonomy"  "Medium"    "Transect"  "Station"   "Substrate"
## [25] "Type"
antibio_neg <- Gram_neg_SIR_diameter[, c(1:19)]
antibio_neg_meta <- Gram_neg_SIR_diameter[, c(20:25)]
row.names(antibio_neg_meta) <- Gram_neg_SIR_diameter$Sample.ID

##Dealing with the missing values

library(VIM)
library(FactoMineR)
library(missMDA)
library(naniar)
library(ggfortify)

summary(antibio_neg)
##   Sample.ID             NA.                 AN                AUG           
##  Length:78          Length:78          Length:78          Length:78         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      ATM                FEP                FOX                CIP           
##  Length:78          Length:78          Length:78          Length:78         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      SXT                ETP                 FF                 CN           
##  Length:78          Length:78          Length:78          Length:78         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      IPM                LEV                PIP                PTZ           
##  Length:78          Length:78          Length:78          Length:78         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      TIC                TCC                TOB           
##  Length:78          Length:78          Length:78         
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character
dim(na.omit(antibio_neg)) #How many lines and column do I keep if I remove all the missing values
## [1] 35 19
p01 <- gg_miss_var(antibio_neg) #plot of missing data 
p01

res<-summary(aggr(antibio_neg, sortVar=TRUE))$combinations

## 
##  Variables sorted by number of missings: 
##   Variable      Count
##         AN 0.53846154
##        FOX 0.43589744
##        PIP 0.42307692
##         FF 0.39743590
##        TCC 0.38461538
##        AUG 0.37179487
##        ETP 0.37179487
##        NA. 0.33333333
##        TOB 0.32051282
##        PTZ 0.29487179
##        TIC 0.29487179
##        SXT 0.20512821
##        ATM 0.10256410
##        IPM 0.08974359
##         CN 0.07692308
##        CIP 0.03846154
##        FEP 0.02564103
##        LEV 0.02564103
##  Sample.ID 0.00000000
head(res[rev(order(res[,2])),]) # Only 12 % of the dataset has no holes 
##                             Combinations Count   Percent
## 1  0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0    35 44.871795
## 9  0:1:1:1:0:0:1:0:1:1:1:0:0:0:1:1:1:1:1    12 15.384615
## 3  0:0:1:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0     8 10.256410
## 11 0:1:1:1:1:0:1:0:0:1:1:0:0:0:1:0:0:1:0     6  7.692308
## 8  0:1:1:1:0:0:1:0:0:1:1:1:1:0:1:1:1:1:1     5  6.410256
## 5  0:0:1:0:0:0:1:0:0:0:1:0:0:0:1:0:0:0:1     4  5.128205

R-I-S intepreted analysis

Load antibiogram table

Gram_neg_SIR <- read.table("/Users/qcvp/R/Mẫu RIVS/báo20192020/negative.txt", sep = "\t", header = T)
names(Gram_neg_SIR)
##  [1] "Sample.ID" "NA."       "AN"        "AUG"       "ATM"       "FEP"      
##  [7] "FOX"       "CIP"       "SXT"       "ETP"       "FF"        "CN"       
## [13] "IPM"       "LEV"       "PIP"       "PTZ"       "TIC"       "TCC"      
## [19] "TOB"       "Taxonomy"  "Medium"    "Transect"  "Station"   "Substrate"
## [25] "Type"
row.names(Gram_neg_SIR) <- Gram_neg_SIR$Sample.ID
Gram_neg_SIR2 <- Gram_neg_SIR[,-1]

Setup

library(dplyr)
names(Gram_neg_SIR)
##  [1] "Sample.ID" "NA."       "AN"        "AUG"       "ATM"       "FEP"      
##  [7] "FOX"       "CIP"       "SXT"       "ETP"       "FF"        "CN"       
## [13] "IPM"       "LEV"       "PIP"       "PTZ"       "TIC"       "TCC"      
## [19] "TOB"       "Taxonomy"  "Medium"    "Transect"  "Station"   "Substrate"
## [25] "Type"
#Media
med_neg_res <- data.frame("Aero" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="Aero",1:18], 2, function(x) (length(which(x == "R"))/length(x))),
                      "MA" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="MA",1:18], 2, function(x) (length(which(x == "R"))/length(x))),
                      "MAC" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="MAC",1:18], 2, function(x) (length(which(x == "R"))/length(x))),
                      "SS" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="SS",1:18], 2, function(x) (length(which(x == "R"))/length(x))),
                      "Antibiotic" = names(Gram_neg_SIR2[,1:18]))

#Sample types
sampletypes_neg_res <- data.frame(
  "Environment" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Type =="Environment",1:18], 2, function(x) (length(which(x == "R"))/length(which(x %in% c("R", "S", "I"))))),
                      "Antibiotic" = names(Gram_neg_SIR2[,1:18]))
antibiotic_class <- rep("Fluoroquinolones", 18)
antibiotic_class[med_neg_res$Antibiotic %in% c("AUG", "PIP", "TCC", "TIC", "PTZ")] <- "Penicillins"
antibiotic_class[med_neg_res$Antibiotic %in% c("FEP", "FOX")] <- "Cephalosporins"
antibiotic_class[med_neg_res$Antibiotic %in% c("AN", "TOB", "CN")] <- "Aminoglycosides"
antibiotic_class[med_neg_res$Antibiotic %in% c("ATM")] <- "Monobactams"
antibiotic_class[med_neg_res$Antibiotic %in% c("ETP", "IPM")] <- "Carbapenems"
antibiotic_class[med_neg_res$Antibiotic %in% c("CIP", "LEV" ,"NA.")] <- "Fluoroquinolones"
antibiotic_class[med_neg_res$Antibiotic %in% c("FF","SXT")] <- "Others"

med_neg_res$antibiotic_class <- antibiotic_class
sampletypes_neg_res$antibiotic_class <- antibiotic_class
rm(antibiotic_class)

Barplot resistant percentage

library(tidyr)
med_neg_res_mac <- gather(med_neg_res, Medium, Resistant, MAC)
med_neg_res_ae <- gather(med_neg_res, Medium, Resistant, Aero)
med_neg_res_ma <- gather(med_neg_res, Medium, Resistant, MA)
med_neg_res_ss <- gather(med_neg_res, Medium, Resistant, SS)
library(ggplot2)
p1 <- ggplot(med_neg_res_mac, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Mac-Conkey isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p1

p2 <- ggplot(med_neg_res_ma, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Marine Agar isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p2

p3 <- ggplot(med_neg_res_ae, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Aeromonas isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p3

p4 <- ggplot(med_neg_res_ss, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Salmonella Shigella isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p4

Combine

library(tidyr)
med_neg_res_long <- gather(med_neg_res, Medium, Resistant, c(Aero, MA, MAC, SS))
#plot
p5 <- ggplot(med_neg_res_long, aes(x = Antibiotic, y = Resistant, fill= Medium)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13)) +
  facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x")
p5

MAR index bar plot

Total

Gram_neg_SIR3 <- Gram_neg_SIR2 %>% separate(Taxonomy, c("Genus", "Species"))
# Adding color for plotting
custom_colors <- c( "#CBD588", "#5F7FC7","#DA5724", "#508578", "#CD9BCD",
                    "#AD6F3B", "#673770","#D14285", "#652926", "#C84248", 
                    "#8569D5", "#5E738F","#D1A33D", "#8A7C64", "#599861", "black", "red", "green")

# MAR calculate
Gram_neg_SIR3$MAR <- apply(Gram_neg_SIR3[,1:18], 1, function(x) (length(which(x == "R"))/length(which(x %in% c("R", "S", "I")))))

# Plotting Transect
box3 = ggplot(Gram_neg_SIR3, aes(x = Transect , y = MAR, color = Transect)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Transect), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=13),
        axis.text.x = element_blank()) + 
    ylab("MAR index") + scale_fill_manual(values = custom_colors) +   geom_hline(yintercept = 0.2, linetype="dashed") 
  #facet_wrap(~Transect, nrow=1, scales = "free_x")
box3

# Plotting face wrap with Sample type
box4 = ggplot(Gram_neg_SIR3, aes(x = Transect , y = MAR, color = Transect)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Transect), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=13),
        axis.text.x = element_blank()) + 
    ylab("MAR index") + scale_fill_manual(values = custom_colors) +   geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Substrate, nrow=1, scales = "free_x")
box4

Plotting with Genus in each Transect

Gram_neg_SIR3_farm <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Farm", ]
Gram_neg_SIR3_urban <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Urban", ]
Gram_neg_SIR3_recovery <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Recovery", ]

box5 = ggplot(Gram_neg_SIR3_farm, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Farm MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box5

box6 = ggplot(Gram_neg_SIR3_urban, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Urban MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box6

box5 = ggplot(Gram_neg_SIR3_recovery, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Recovery MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box5

# Positive bacteria Processing data

Gram_neg_SIR_diameter <- read.table("/Users/qcvp/R/Mẫu RIVS/báo20192020/positive.txt", sep = "\t", header = T)
names(Gram_neg_SIR_diameter)
##  [1] "Samples_ID" "CIP"        "SXT"        "ETP"        "FF"        
##  [6] "CN"         "IMP"        "K"          "LEV"        "R"         
## [11] "T"          "TOB"        "Taxonomy"   "Medium"     "Transect"  
## [16] "Station"    "Type"       "Substrate"
antibio_neg <- Gram_neg_SIR_diameter[, c(1:12)]

##Dealing with the missing values

library(VIM)
library(FactoMineR)
library(missMDA)
library(naniar)
library(ggfortify)

summary(antibio_neg)
##   Samples_ID            CIP                SXT                ETP           
##  Length:61          Length:61          Length:61          Length:61         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##       FF                 CN                IMP                 K            
##  Length:61          Length:61          Length:61          Length:61         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      LEV                 R                  T                 TOB           
##  Length:61          Length:61          Length:61          Length:61         
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character
dim(na.omit(antibio_neg)) #How many lines and column do I keep if I remove all the missing values
## [1]  0 12
p01 <- gg_miss_var(antibio_neg) #plot of missing data 
p01

res<-summary(aggr(antibio_neg, sortVar=TRUE))$combinations

## 
##  Variables sorted by number of missings: 
##    Variable     Count
##         IMP 0.4262295
##         TOB 0.4098361
##         CIP 0.3770492
##         LEV 0.3770492
##         ETP 0.2131148
##           K 0.2131148
##           R 0.2131148
##  Samples_ID 0.0000000
##         SXT 0.0000000
##          FF 0.0000000
##          CN 0.0000000
##           T 0.0000000
head(res[rev(order(res[,2])),]) # Only 12 % of the dataset has no holes 
##              Combinations Count   Percent
## 4 0:1:0:0:0:0:1:0:1:0:0:0    23 37.704918
## 1 0:0:0:0:0:0:0:0:0:0:0:1    22 36.065574
## 3 0:0:0:1:0:0:0:1:0:1:0:0    13 21.311475
## 2 0:0:0:0:0:0:1:0:0:0:0:1     3  4.918033

R-I-S intepreted analysis

Load antibiogram table

Gram_neg_SIR <- read.table("/Users/qcvp/R/Mẫu RIVS/báo20192020/positive.txt", sep = "\t", header = T)
names(Gram_neg_SIR)
##  [1] "Samples_ID" "CIP"        "SXT"        "ETP"        "FF"        
##  [6] "CN"         "IMP"        "K"          "LEV"        "R"         
## [11] "T"          "TOB"        "Taxonomy"   "Medium"     "Transect"  
## [16] "Station"    "Type"       "Substrate"
row.names(Gram_neg_SIR) <- Gram_neg_SIR$Sample.ID
Gram_neg_SIR2 <- Gram_neg_SIR[,-1]

Setup

library(dplyr)
names(Gram_neg_SIR)
##  [1] "Samples_ID" "CIP"        "SXT"        "ETP"        "FF"        
##  [6] "CN"         "IMP"        "K"          "LEV"        "R"         
## [11] "T"          "TOB"        "Taxonomy"   "Medium"     "Transect"  
## [16] "Station"    "Type"       "Substrate"
#Media
med_neg_res <- data.frame("Aero" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="Aero",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "MA" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="MA",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "MAC" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="MAC",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "SS" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="SS",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "TCBS" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="TCBS",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "Sta" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Medium =="Sta",1:11], 2, function(x) (length(which(x == "R"))/length(x))),
                      "Antibiotic" = names(Gram_neg_SIR2[,1:11]))

#Sample types
sampletypes_neg_res <- data.frame(
  "Environment" = apply(Gram_neg_SIR2[Gram_neg_SIR2$Type =="Environment",1:11], 2, function(x) (length(which(x == "R"))/length(which(x %in% c("R", "S", "I"))))),
                      "Antibiotic" = names(Gram_neg_SIR2[,1:11]))
antibiotic_class <- rep("Fluoroquinolones", 11)
antibiotic_class[med_neg_res$Antibiotic %in% c("R", "E")] <- "Macrolides "
antibiotic_class[med_neg_res$Antibiotic %in% c("TOB", "CN", "K")] <- "Aminoglycosides"
antibiotic_class[med_neg_res$Antibiotic %in% c("IMP")] <- "Carbapenems"
antibiotic_class[med_neg_res$Antibiotic %in% c("CIP", "LEV")] <- "Fluoroquinolones"
antibiotic_class[med_neg_res$Antibiotic %in% c("FF")] <- "Phosphonic antibiotics"
antibiotic_class[med_neg_res$Antibiotic %in% c("SXT", "T")] <- "Others"

med_neg_res$antibiotic_class <- antibiotic_class
sampletypes_neg_res$antibiotic_class <- antibiotic_class
rm(antibiotic_class)

Barplot resistant percentage

library(tidyr)
med_neg_res_mac <- gather(med_neg_res, Medium, Resistant, MAC)
med_neg_res_ae <- gather(med_neg_res, Medium, Resistant, Aero)
med_neg_res_ma <- gather(med_neg_res, Medium, Resistant, MA)
med_neg_res_ss <- gather(med_neg_res, Medium, Resistant, SS)
med_neg_res_tcbs <- gather(med_neg_res, Medium, Resistant, TCBS)
med_neg_res_sta <- gather(med_neg_res, Medium, Resistant, Sta)
library(ggplot2)
p1 <- ggplot(med_neg_res_mac, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Mac-Conkey isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p1

p2 <- ggplot(med_neg_res_ma, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Marine Agar isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p2

p3 <- ggplot(med_neg_res_ae, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Aeromonas isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p3

p4 <- ggplot(med_neg_res_ss, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Salmonella Shigella isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p4

p5 <- ggplot(med_neg_res_tcbs, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Thiosulfate-Citrate-Bile-Salt Sucrose isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p5

p6 <- ggplot(med_neg_res_sta, aes(x = Antibiotic, y = Resistant)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Streptomycin Thallous Acetate isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() + facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x") +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13))
p6

Combine

library(tidyr)
med_neg_res_long <- gather(med_neg_res, Medium, Resistant, c(Aero, MA, MAC, SS, TCBS, Sta))
#plot
p7 <- ggplot(med_neg_res_long, aes(x = Antibiotic, y = Resistant, fill= Medium)) + 
  geom_bar(stat = "identity", position=position_dodge()) +
  ylab("Isolates resistance") +
  scale_y_continuous(expand = c(0,0), labels = scales::percent_format(scale = 100)) +
  theme_bw() +
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=15),
        axis.text.x = element_text(angle=30, colour = "black", vjust=1, hjust = 1, size=13)) +
  facet_grid(~ antibiotic_class, space = "free_x", scales = "free_x")
p7

MAR index bar plot

Total

Gram_neg_SIR3 <- Gram_neg_SIR2 %>% separate(Taxonomy, c("Genus", "Species"))
## Warning: Expected 2 pieces. Additional pieces discarded in 16 rows [8, 18, 19, 29, 30,
## 31, 32, 33, 36, 41, 46, 47, 49, 54, 58, 60].
# Adding color for plotting
custom_colors <- c( "#CBD588", "#5F7FC7","#DA5724", "#508578", "#CD9BCD",
                    "#AD6F3B", "#673770","#D14285", "#652926", "#C84248", 
                    "#8569D5", "#5E738F","#D1A33D", "#8A7C64", "#599861", "black", "red", "green")

# MAR calculate
Gram_neg_SIR3$MAR <- apply(Gram_neg_SIR3[,1:11], 1, function(x) (length(which(x == "R"))/length(which(x %in% c("R", "S", "I")))))

# Plotting Transect
box3 = ggplot(Gram_neg_SIR3, aes(x = Transect , y = MAR, color = Transect)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Transect), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=13),
        axis.text.x = element_blank()) + 
    ylab("MAR index") + scale_fill_manual(values = custom_colors) +   geom_hline(yintercept = 0.2, linetype="dashed") 
  #facet_wrap(~Transect, nrow=1, scales = "free_x")
box3

# Plotting face wrap with Sample type
box4 = ggplot(Gram_neg_SIR3, aes(x = Transect , y = MAR, color = Transect)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Transect), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 15),
        axis.text.y = element_text(size=13),
        axis.text.x = element_blank()) + 
    ylab("MAR index") + scale_fill_manual(values = custom_colors) +   geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Substrate, nrow=1, scales = "free_x")
box4

Plotting with Genus in each Transect

Gram_neg_SIR3_farm <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Farm", ]
Gram_neg_SIR3_urban <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Urban", ]
Gram_neg_SIR3_recovery <- Gram_neg_SIR3[Gram_neg_SIR2$Transect == "Recovery", ]

box5 = ggplot(Gram_neg_SIR3_farm, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Farm MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box5

box6 = ggplot(Gram_neg_SIR3_urban, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Urban MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box6

box5 = ggplot(Gram_neg_SIR3_recovery, aes(x = Genus , y = MAR, color = Genus)) + 
  geom_jitter(position = position_jitter(width = .20), alpha = 0.5, size = 3) + theme_bw() +
  geom_boxplot(aes(colour = Genus), alpha=0.1, outlier.colour = NA) + 
  theme(axis.title.x = element_blank(),
        axis.title.y = element_text(size = 20),
        axis.text.y = element_text(size=20),
        axis.text.x = element_blank()) + 
  ggtitle("Recovery MAR") +
  ylab("MAR index") + scale_fill_manual(values = custom_colors) + #theme(legend.position="bottom") +
  geom_hline(yintercept = 0.2, linetype="dashed") +
  facet_wrap(~Type, nrow=1, scales = "free_x")
box5