line-plots-milti-panel.R 2.86 KB
# Based on http://zevross.com/blog/2019/04/02/easy-multi-panel-plots-in-r-using-facet_wrap-and-facet_grid-from-ggplot2/

library(ggplot2)
#library(ggpubr)
#library(cowplot)

organism = 'ECO'

if (organism == 'ECO') {
######### ECO DEVELOPMENT DATASET ##########

# ECO-DEV-WITH-EFFECT-COMBINATION: Combination of strategies with effect in E. coli development dataset
df <- data.frame(Panel=rep(c("Combination of strategies (effect)", "Separated strategies (effect)", "Combination of strategies (no effect)", "Separated strategies (no effect)"), each=12),
                Measure=rep(c("Precision", "Recall", "F1-score"), each=4),
                Strategy=c(rep(c("D", "D+V", "D+V+At", "D+V+At+Au"),3),rep(c("D", "V", "At", "Au"),3)),
                Score=c(
                0.78, 0.79, 0.81, 0.81, 0.41, 0.56, 0.63, 0.63, 0.53, 0.65, 0.71, 0.71,
                0.78, 0.89, 0.93, 1.00, 0.41, 0.35, 0.13, 0.01, 0.53, 0.50, 0.23, 0.02,
                0.82, 0.82, 0.84, 0.84, 0.55, 0.66, 0.72, 0.72, 0.66, 0.73, 0.78, 0.78,
                0.82, 0.88, 0.94, 1.00, 0.55, 0.39, 0.20, 0.01, 0.66, 0.54, 0.33, 0.02))
filename = "ECO-dev-multi-panel.png"
title_plot = "E. coli development dataset"
} else if (organism == 'STM')
{
######### STM DEVELOPMENT DATASET ##########

# STM-DEV-WITH-EFFECT-COMBINATION: Combination of strategies with effect in Salmonella evaluation dataset
df <- data.frame(Panel=rep(c("Combination of strategies (effect)", "Separated strategies (effect)", "Combination of strategies (no effect)", "Separated strategies (no effect)"), each=12),
                Measure=rep(c("Precision", "Recall", "F1-score"), each=4),
                Strategy=c(rep(c("D", "D+V", "D+V+At", "D+V+At+Au"),3),rep(c("D", "V", "At", "Au"),3)),
                Score=c(
                0.78, 0.77, 0.76, 0.76, 0.33, 0.49, 0.54, 0.54, 0.47, 0.60, 0.63, 0.63,
                0.78, 0.81, 0.70, 0.88, 0.33, 0.33, 0.10, 0.01, 0.47, 0.47, 0.18, 0.02,
                0.84, 0.82, 0.81, 0.81, 0.47, 0.59, 0.65, 0.65, 0.60, 0.68, 0.72, 0.72,
                0.84, 0.84, 0.77, 0.86, 0.47, 0.40, 0.17, 0.01, 0.60, 0.55, 0.27, 0.02))
filename = "STM-dev-multi-panel.png"
title_plot = "Salmonella evaluation dataset"
}

head(df)

pa<-ggplot(df, aes(x=Strategy, y=Score, group=Measure)) +
  geom_line(aes(color=Measure))+
  geom_point(aes(color=Measure))+
  scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9"))+
  #scale_color_manual(values=c("#e6194b", "#3cb44b", "#0082c8"))+
  geom_text(aes(label = Score))+
  labs(title=title_plot,x="Strategies", y = "Score")+
  #theme_classic()+
  theme(
  legend.position="top",
  # Centrar título: plot.title = element_text(hjust = 0.5),
  axis.line = element_line(colour = "gray"),
  panel.background = element_blank(),
  panel.grid.major = element_blank(),
  panel.grid.minor = element_blank(),
  panel.border = element_blank(),
  )+
  facet_wrap(~Panel, scale="free")

ggsave(filename)