comparison barplot.r @ 10:fd4a60fc3fca draft default tip

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit cf30b4fab90cf7910bb2900a05b85ca3344aae59
author artbio
date Tue, 15 Nov 2022 00:45:36 +0000
parents 3bddd7ab96e3
children
comparison
equal deleted inserted replaced
9:6bf9de09aa74 10:fd4a60fc3fca
1 if (length(commandArgs(TRUE)) == 0) { 1 if (length(commandArgs(TRUE)) == 0) {
2 system("Rscript barplot.r -h", intern = F) 2 system("Rscript barplot.r -h", intern = FALSE)
3 q("no") 3 q("no")
4 } 4 }
5 5
6 # load packages that are provided in the conda env 6 # load packages that are provided in the conda env
7 options(show.error.messages = F, 7 options(show.error.messages = FALSE,
8 error = function() { 8 error = function() {
9 cat(geterrmessage(), file = stderr()) 9 cat(geterrmessage(), file = stderr())
10 q("no", 1, F) 10 q("no", 1, FALSE)
11 } 11 }
12 ) 12 )
13 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") 13 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
14 warnings() 14 warnings()
15 library(optparse) 15 library(optparse)
33 ) 33 )
34 34
35 opt <- parse_args(OptionParser(option_list = option_list), 35 opt <- parse_args(OptionParser(option_list = option_list),
36 args = commandArgs(trailingOnly = TRUE)) 36 args = commandArgs(trailingOnly = TRUE))
37 37
38 annotations <- read.delim(opt$input, header = F) 38 annotations <- read.delim(opt$input, header = FALSE)
39 colnames(annotations) <- c("sample", "class", "percent_of_reads", "total") 39 colnames(annotations) <- c("sample", "class", "percent_of_reads", "total")
40 annotations$percent <- round(annotations$percent_of_reads / annotations$total * 100, 40 annotations$percent <- round(annotations$percent_of_reads / annotations$total * 100,
41 digits = 2) 41 digits = 2)
42 ## ggplot2 plotting 42 ## ggplot2 plotting
43 43
49 ggtitle("Class proportions") 49 ggtitle("Class proportions")
50 ggplot(annotations, aes(x = total / 2, y = percent_of_reads, fill = class, width = total)) + 50 ggplot(annotations, aes(x = total / 2, y = percent_of_reads, fill = class, width = total)) +
51 geom_bar(position = "fill", stat = "identity") + 51 geom_bar(position = "fill", stat = "identity") +
52 facet_wrap(~sample, ncol = 3) + 52 facet_wrap(~sample, ncol = 3) +
53 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5), 53 geom_label_repel(aes(label = percent), position = position_fill(vjust = 0.5),
54 size = 2, show.legend = F) + 54 size = 2, show.legend = FALSE) +
55 coord_polar(theta = "y") + 55 coord_polar(theta = "y") +
56 labs(x = "Class fractions (%)") + 56 labs(x = "Class fractions (%)") +
57 scale_fill_manual(values = mycolors) + 57 scale_fill_manual(values = mycolors) +
58 theme(axis.text = element_blank(), 58 theme(axis.text = element_blank(),
59 axis.ticks = element_blank(), 59 axis.ticks = element_blank(),