suppressWarnings(library(ggplot2))

Portion_labels=c(    "rel_genome_size"="Genome size",
            "rel_analysed_size"="Covered by reads",
            "rel_non_NA_analysed_size"="Featured in windows",
            "rel_informative_positions"="Informative positions" )

Portion_colors=c(    "rel_genome_size"="grey60",
            "rel_analysed_size"="grey30",
            "rel_non_NA_analysed_size"="grey30",
            "rel_informative_positions"="red4" )

y <- read.table("/home/jforment/biovice/internal_projects/240913_fjescmaz_pil/04-manticore/SY05/5_tables/RES.whole.relative_lengths.table")
y <- y[c(2,4,6,8),]
y$V1 <- factor(y$V1, levels=as.character(y$V1))
y <- y[order(y$V1, decreasing=T),]
colnames(y) <- c("Labels", "Values")
y$Labels <- factor(y$Labels, levels=as.character(y$Labels))
y$Values <- as.numeric(as.character(y$Values))

P1 <- ggplot() + 
theme(plot.title=element_text(family="sans", face="bold", colour="grey20", size=13),
axis.title.x=element_text(family="Helvetica", face="plain", colour="grey20", size=10),
axis.title.y=element_text(family="Helvetica", face="plain", colour="grey20", size=10),
axis.text.x=element_text(family="sans", face="plain", colour="grey20", size=11),
axis.text.y=element_text(family="sans", face="italic", colour="grey20", size=11),
legend.text=element_text(family="sans", face="italic", colour="black", size=9),
legend.title=element_text(family="sans", face="plain", colour="black", size=9),
panel.background=element_rect(fill="grey90", colour="grey90"),
aspect.ratio=0.25) + 
ggtitle("SY05, whole") +
xlab("") + 
ylab("Represented genome portions [%]") +
geom_bar(data=y, mapping=aes(x=Labels, y=Values, fill=Labels), width=0.45,
      stat="identity", position=position_dodge(), show.legend = FALSE) +
scale_x_discrete(labels=Portion_labels) +
scale_y_continuous(limits=c(0,100)) +
scale_fill_manual(values=Portion_colors) + 
coord_flip()

basename <- paste("SY05", "frac", "whole", sep=".")

svg(paste("/home/jforment/biovice/internal_projects/240913_fjescmaz_pil/04-manticore/SY05/6_plots", "svg", paste(basename, "svg", sep="."), sep="/"))
plot(P1)
dev.off()

png(paste("/home/jforment/biovice/internal_projects/240913_fjescmaz_pil/04-manticore/SY05/6_plots", "png", paste(basename, "png", sep="."), sep="/"), height=300, width=1000, pointsize=11, units="px", type="cairo", res=220)
suppressWarnings(plot(P1))
dev.off()
