1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| library(ggplot2)
args<-commandArgs(T)
Reads_Table=args[1]
Result_Dir=args[2]
Plot_Sample = args[3]
Data = read.table(Reads_Table, head=T, sep="\t", comment.char="#", stringsAsFactors=FALSE, check.names=FALSE)
List_Color = c("#808080", "#1e90ff") Data$Group = rep("Other Sample", nrow(Data)) Data$Group[with(Data, Sample==Plot_Sample)] = "This Sample" Data$Color = rep(List_Color[1], nrow(Data)) Data$Color[with(Data, Sample==Plot_Sample)] = List_Color[2] if (nrow(Data) == 1){ List_Color = List_Color[2] }
plot_font_size=10 if (plot_font_size < 10) { plot_font_size = 10 } universal_theme=theme_bw(base_size=plot_font_size)+ theme(axis.line=element_line(size=0.5,colour='black'))+ theme(axis.title.x=element_text(size=plot_font_size-2),axis.title.y=element_text(size=plot_font_size-2))+ theme(axis.text.x=element_text(size=plot_font_size-3,colour='black'),axis.text.y=element_text(size=plot_font_size-3,colour='black'))+ theme(legend.key.size=unit(20,"pt"),legend.title=element_text(size=plot_font_size-2),legend.text=element_text(size=plot_font_size-3))+ theme(panel.border=element_blank())+ theme(plot.title=element_text(hjust=0.5,size=plot_font_size))+ theme(legend.position="none")+ theme(panel.grid=element_blank())
picture = ggplot(data=Data, aes(x=Sample, y=Reads, fill=Group)) + geom_bar(stat="identity", width=0.7) + labs(x="", y="", title="无乳链球菌") + scale_y_continuous(expand = c(0,0)) + scale_fill_manual(values = List_Color) + universal_theme + theme(axis.text.y = element_text(colour = rev(Data$Color))) + coord_flip()
output_png = paste(Result_Dir, "/", "无乳链球菌.png", sep="", collapse="") ggsave(output_png, picture, width=8, height=10)
|