comparison barplot.r @ 6:8829656d6999 draft

"planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 60340e9e0d2795b88e23fd57e1ccb190918bf337"
author artbio
date Mon, 07 Oct 2019 08:40:41 -0400
parents e11f91575af6
children 3bddd7ab96e3
comparison
equal deleted inserted replaced
5:279fdd92a615 6:8829656d6999
10 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") 10 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
11 warnings() 11 warnings()
12 library(optparse) 12 library(optparse)
13 library(ggplot2) 13 library(ggplot2)
14 library(ggrepel) 14 library(ggrepel)
15 library(RColorBrewer)
15 16
16 17
17 #Arguments 18 #Arguments
18 option_list = list( 19 option_list = list(
19 make_option( 20 make_option(
37 ## 38 ##
38 annotations = read.delim(opt$input, header=F) 39 annotations = read.delim(opt$input, header=F)
39 colnames(annotations) = c("sample", "class", "percent_of_reads", "total") 40 colnames(annotations) = c("sample", "class", "percent_of_reads", "total")
40 annotations$percent=round(annotations$percent_of_reads/annotations$total*100, digits=2) 41 annotations$percent=round(annotations$percent_of_reads/annotations$total*100, digits=2)
41 # ggplot2 plotting 42 # ggplot2 plotting
43
44 # Define the number of colors you want
45 Sasha.Trubetskoy.Palette <- c('#e6194b', '#3cb44b', '#ffe119', '#4363d8', '#f58231',
46 '#911eb4', '#46f0f0', '#f032e6', '#bcf60c',
47 '#008080', '#e6beff', '#9a6324', '#fffac8', '#800000',
48 '#aaffc3', '#808000', '#ffd8b1', '#000075', '#808080')
49 nb.cols <- 19 # 10 with colorRampPalette
50 # mycolors <- colorRampPalette(brewer.pal(8, "Paired"))(nb.cols)
51 mycolors <- Sasha.Trubetskoy.Palette[1:nb.cols]
52
42 ggtitle('Class proportions') 53 ggtitle('Class proportions')
43 ggplot(annotations, aes(x=total/2, y = percent_of_reads, fill = class, width = total)) + 54 ggplot(annotations, aes(x=total/2, y = percent_of_reads, fill = class, width = total)) +
44 geom_bar(position="fill", stat="identity") + 55 geom_bar(position="fill", stat="identity") +
45 facet_wrap(~sample, ncol=3 ) + geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), size=2,show.legend = F) + 56 facet_wrap(~sample, ncol=3 ) +
57 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), size=2,show.legend = F) +
46 coord_polar(theta="y") + 58 coord_polar(theta="y") +
47 labs(x = "Class fractions (%)") + 59 labs(x = "Class fractions (%)") +
60 scale_fill_manual(values = mycolors) +
48 theme(axis.text = element_blank(), 61 theme(axis.text = element_blank(),
49 axis.ticks = element_blank(), 62 axis.ticks = element_blank(),
50 panel.grid = element_blank(), 63 panel.grid = element_blank(),
51 axis.title.y = element_blank(), 64 axis.title.y = element_blank(),
52 legend.position="bottom") + 65 legend.position="bottom") +