comparison barplot.r @ 4:e11f91575af6 draft

planemo upload for repository https://github.com/ARTbio/tools-artbio/tree/master/tools/sr_bowtie_dataset_annotation commit 618a7892f6af26278364a75ab23b3c6d8cdc73db
author artbio
date Wed, 20 Mar 2019 07:12:53 -0400
parents 008de522b3ea
children 8829656d6999
comparison
equal deleted inserted replaced
3:008de522b3ea 4:e11f91575af6
9 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } ) 9 error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
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(scales) 14 library(ggrepel)
15
16 15
17 16
18 #Arguments 17 #Arguments
19 option_list = list( 18 option_list = list(
20 make_option( 19 make_option(
35 args = commandArgs(trailingOnly = TRUE)) 34 args = commandArgs(trailingOnly = TRUE))
36 35
37 36
38 ## 37 ##
39 annotations = read.delim(opt$input, header=F) 38 annotations = read.delim(opt$input, header=F)
40 colnames(annotations) = c("class", "counts") 39 colnames(annotations) = c("sample", "class", "percent_of_reads", "total")
41 annotations = cbind(annotations, fraction=annotations$counts/annotations$counts[1]) 40 annotations$percent=round(annotations$percent_of_reads/annotations$total*100, digits=2)
42 annotations = annotations[-1,]
43 # ggplot2 plotting 41 # ggplot2 plotting
44 ggplot(annotations, aes(x="classes", y=fraction, fill=class)) +
45 geom_bar(width = .7, position=position_stack(), stat = "identity") +
46 geom_text(aes(label = percent(fraction)), position = position_stack(vjust = 0.5),size = 4)
47 ggtitle('Class proportions') 42 ggtitle('Class proportions')
43 ggplot(annotations, aes(x=total/2, y = percent_of_reads, fill = class, width = total)) +
44 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) +
46 coord_polar(theta="y") +
47 labs(x = "Class fractions (%)") +
48 theme(axis.text = element_blank(),
49 axis.ticks = element_blank(),
50 panel.grid = element_blank(),
51 axis.title.y = element_blank(),
52 legend.position="bottom") +
53 geom_text(aes(x = total/2, y= .5, label = paste(round(total/1000000, digits=3), "M"), vjust = 4, hjust=-1), size=2)
48 ggsave(file=opt$barplot, device="pdf") 54 ggsave(file=opt$barplot, device="pdf")
55