diff --git a/README.md b/README.md index d9d46e2..3c7e2a0 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ ### s-plot -===== +--- + A simple plot library based on `bash`, `R` mainly `ggplot2` to make the plot easily and flexibly. @@ -18,11 +19,13 @@ ${filename} colorBar #### Lines ${filename} lines +${filename} lines_lm #### Dots ${filename} pca ${filename} scatterplot ${filename} scatterplot2 +${filename} scatterplot3d ${filename} scatterplotColor ${filename} scatterplotContour ${filename} scatterplotLotsData @@ -33,6 +36,7 @@ ${filename} contourPlot #### Distribution ${filename} areaplot ${filename} boxplot +${filename} density2d ${filename} densityPlot ${filename} densityHistPlot ${filename} histogram @@ -48,11 +52,20 @@ ${filename} heatmapM ${filename} heatmap.2 ${filename} pheatmap ${filename} pretteyHeatmap +${filename} areaplot.new + +### ecrichplot +${filename} enrichmentPlot #### Others ${filename} volcano ${filename} vennDiagram ${filename} upsetView + +and other tools: +${filename} png2eps +${filename} boxplot.statistics +${filename} colorLegend ``` #### Basic test data set diff --git a/e b/e deleted file mode 100644 index e69de29..0000000 diff --git a/error.txt b/error.txt new file mode 100644 index 0000000..0e50a20 --- /dev/null +++ b/error.txt @@ -0,0 +1 @@ +sp_pheatmap:参数-G 丢失 diff --git a/example/.DS_Store b/example/.DS_Store new file mode 100644 index 0000000..aca3bae Binary files /dev/null and b/example/.DS_Store differ diff --git a/example/areaplot/areaplot.data b/example/areaplot/areaplot.data new file mode 100644 index 0000000..2cca5cd --- /dev/null +++ b/example/areaplot/areaplot.data @@ -0,0 +1,7 @@ +len known_unexpr known_expr new group +30 1 0 0 1 +42 1 0 0 1 +45 3 0 0 1 +46 1 0 0 1 +48 2 0 0 1 +49 1 0 0 1 diff --git a/example/barplot/barplot.melt.data b/example/barplot/barplot.melt.data new file mode 100644 index 0000000..549202f --- /dev/null +++ b/example/barplot/barplot.melt.data @@ -0,0 +1,21 @@ +Pos variable value Set +-5000 h3k27ac 8.71298 +-4000 h3k27ac 8.43246 +-3000 h3k27ac 8.25497 +-2000 h3k27ac 7.16265 +-1000 h3k27ac 3.55341 +0 h3k27ac 3.55030 +1000 h3k27ac 7.07502 +2000 h3k27ac 8.24328 +3000 h3k27ac 8.43869 +4000 h3k27ac 8.48877 +-5000 ctcf 10.69130 +-4000 ctcf 10.76680 +-3000 ctcf 10.54410 +-2000 ctcf 10.86350 +-1000 ctcf 8.45751 +0 ctcf 8.50316 +1000 ctcf 10.91430 +2000 ctcf 10.70220 +3000 ctcf 10.41010 +4000 ctcf 10.57570 diff --git a/example/barplot/barplot.normal.data b/example/barplot/barplot.normal.data new file mode 100644 index 0000000..6fc0b67 --- /dev/null +++ b/example/barplot/barplot.normal.data @@ -0,0 +1,11 @@ +Pos h3k27ac ctcf enhancer h3k4me3 polII +-5000 8.71298 10.69130 11.7359 10.02510 8.26866 +-4000 8.43246 10.76680 11.8442 9.76927 7.78358 +-3000 8.25497 10.54410 12.2470 9.40346 6.96859 +-2000 7.16265 10.86350 12.6889 8.35070 4.84365 +-1000 3.55341 8.45751 12.8372 4.84680 1.26110 +0 3.55030 8.50316 13.4152 5.17401 1.50022 +1000 7.07502 10.91430 12.3588 8.13909 4.88096 +2000 8.24328 10.70220 12.3888 9.47255 7.67968 +3000 8.43869 10.41010 11.9760 9.80665 7.94148 +4000 8.48877 10.57570 11.6562 9.71986 8.17849 diff --git a/example/boxplot.statistics/boxplot.statistics.data b/example/boxplot.statistics/boxplot.statistics.data new file mode 100644 index 0000000..2da9fc1 --- /dev/null +++ b/example/boxplot.statistics/boxplot.statistics.data @@ -0,0 +1,9 @@ +Gene hmC expr Set +NM_001003918_26622 0 83.1269257376101 TP16 +NM_001011535_3260 0 0 TP16 +NM_001012640_14264 0 0 TP16 +NM_001012640_30427 0 0 TP16 +NM_001003918_2662217393_30486 0 0 TP16 +NM_001017393_30504 0 0 TP16 +NM_001025241_30464 0 0 TP16 +NM_001017393_30504001025241_30513 0 0 TP16 diff --git a/example/boxplot.statistics/boxplot.statistics.melt.data b/example/boxplot.statistics/boxplot.statistics.melt.data new file mode 100644 index 0000000..1b885d9 --- /dev/null +++ b/example/boxplot.statistics/boxplot.statistics.melt.data @@ -0,0 +1,5 @@ +value variable Set +0 hmC g +1 expr g +2 hmC a +3 expr a diff --git a/example/boxplot/.DS_Store b/example/boxplot/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/example/boxplot/.DS_Store differ diff --git a/example/boxplot/boxplot.matrix2.data b/example/boxplot/boxplot.matrix2.data new file mode 100644 index 0000000..2da9fc1 --- /dev/null +++ b/example/boxplot/boxplot.matrix2.data @@ -0,0 +1,9 @@ +Gene hmC expr Set +NM_001003918_26622 0 83.1269257376101 TP16 +NM_001011535_3260 0 0 TP16 +NM_001012640_14264 0 0 TP16 +NM_001012640_30427 0 0 TP16 +NM_001003918_2662217393_30486 0 0 TP16 +NM_001017393_30504 0 0 TP16 +NM_001025241_30464 0 0 TP16 +NM_001017393_30504001025241_30513 0 0 TP16 diff --git a/example/boxplot/boxplot.melt.data b/example/boxplot/boxplot.melt.data new file mode 100644 index 0000000..d54a1df --- /dev/null +++ b/example/boxplot/boxplot.melt.data @@ -0,0 +1,19 @@ +Gene Sample Group Expr Rep +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 diff --git a/example/boxplot/boxplot.melt.data.Expr_Group.boxplot_jitter.pdf b/example/boxplot/boxplot.melt.data.Expr_Group.boxplot_jitter.pdf new file mode 100644 index 0000000..bfc0915 Binary files /dev/null and b/example/boxplot/boxplot.melt.data.Expr_Group.boxplot_jitter.pdf differ diff --git a/example/boxplot/boxplot.melt.data.Expr_Group.jitter.pdf b/example/boxplot/boxplot.melt.data.Expr_Group.jitter.pdf new file mode 100644 index 0000000..2eed358 Binary files /dev/null and b/example/boxplot/boxplot.melt.data.Expr_Group.jitter.pdf differ diff --git a/example/boxplot/boxplot.melt.data.Expr_Group.violin_jitter.pdf b/example/boxplot/boxplot.melt.data.Expr_Group.violin_jitter.pdf new file mode 100644 index 0000000..668c833 Binary files /dev/null and b/example/boxplot/boxplot.melt.data.Expr_Group.violin_jitter.pdf differ diff --git a/example/boxplot/boxplot.melt.data.Expr_Group_Group.violin_jitter.r b/example/boxplot/boxplot.melt.data.Expr_Group_Group.violin_jitter.r new file mode 100644 index 0000000..7a2dbb9 --- /dev/null +++ b/example/boxplot/boxplot.melt.data.Expr_Group_Group.violin_jitter.r @@ -0,0 +1,351 @@ +source('/opt/bin/s-plot/rFunction.R') + +if (FALSE){ + installp(c("ggplot2", "reshape2", "scales","ggbeeswarm","dplyr")) +} + +if(FALSE || TRUE || FALSE){ + library(ggbeeswarm) +} +# else if(FALSE){ +# library(ggbeeswarm) +# } + +library(ggplot2) +library(reshape2) +library(scales) +library(dplyr) + +##### add by lindechun + +s_boxplot_median <- function(dat, more_v=TRUE){ + + ## errorbar(replace median line of boxplot or violin) adapt to sub-xvariable + + errorbarWidth <- function(x){ + y<-mean(unique(x)) + dfd <- function(i,y){ + (i-y)*(0.75/length(unique(x))) + } + cc<-sapply(x,dfd,y) + return(cc) + } + if (more_v){ + temp1 <- mutate(dat,a1=as.integer(Group)) + temp1 <- mutate(temp1,a2=as.integer(Group)) + temp1$a3 <- temp1$a1+errorbarWidth(temp1$a2) + temp2 <- temp1 %>% group_by(a3) %>% summarise(median=median(Expr)) + + ## force boxplots from geom_boxplot to constant width + ## Ref: https://stackoverflow.com/questions/16705129/force-boxplots-from-geom-boxplot-to-constant-width + + if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s") { + tab <- xtabs(~Group+Group+NoMeAnInGTh_I_n_G_s,temp1) + tmp <- temp1[c("Group","Group","Expr","NoMeAnInGTh_I_n_G_s")] + }else{ + tab <- xtabs(~Group+Group,temp1) + tmp <- temp1[c("Group","Group","Expr")] + } + + idx <- which(tab==0,arr.ind=TRUE) + + if(dim(idx)[1] != 0){ + fakeLines <- apply(idx, 1, function(x){ + + if (is.integer(dimnames(tab)[[2]])){ + fake_1 <- as.integer(dimnames(tab)[[2]][x[2]]) + }else{ + fake_1 <- dimnames(tab)[[2]][x[2]] + } + + if (is.integer(dimnames(tab)[[1]])){ + fake_2 <- as.integer(dimnames(tab)[[1]][x[1]]) + }else{ + fake_2 <- dimnames(tab)[[1]][x[1]] + } + if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s") { + if (is.integer(dimnames(tab)[[1]])){ + fake_3 <- as.integer(dimnames(tab)[[3]][x[3]]) + }else{ + fake_3 <- dimnames(tab)[[3]][x[3]] + } + setNames(data.frame(fake_1,fake_2,min(temp1$Expr)-0.06*(max(temp1$Expr)-min(temp1$Expr)),fake_3),names(tmp)) + }else{ + setNames(data.frame(fake_1,fake_2,min(temp1$Expr)-0.06*(max(temp1$Expr)-min(temp1$Expr))),names(tmp)) + } + } + ) + tmp2 <- rbind(tmp, do.call(rbind, fakeLines)) + }else{ + tmp2 <- tmp + } + + return(list(data_m=tmp2,data_bp_median=temp2,data_m_temp=temp1)) + + }else{ + + temp2 <- dat %>% group_by(Group) %>% summarise(median=median(Expr)) + return(list(data_m=dat,data_bp_median=temp2)) + } +} + + +###### add by lindechun + +if(! TRUE){ + ID_var <- c("") + ID_var <- ID_var[ID_var!=""] + data <- read.table(file="boxplot.melt.data", sep="\t", header=TRUE, + row.names=1, quote="", check.names=F) + if ("FALSE" != "FALSE") { + data_m <- as.data.frame(t(data["FALSE", ])) + data_m$Sample = rownames(data_m) + + if ("FALSE" != "FALSE") { + sampleGroup <- read.table("FALSE",sep="\t",header=1,check.names=F,row.names=1) + data_m <- merge(data_m, sampleGroup, by="row.names") + }else{ + print("Wainning: Because per x-axis tag contains only one data, so recommend you to use the scatterplot or lines script") + } + }else { + if ("Group" != "variable") { + if (length(ID_var) > 0){ + ID_var <- c(ID_var, "Group") + } else { + ID_var <- c("Group") + } + data_m <- melt(data, id.vars=ID_var) + } else { + if (length(ID_var) > 0) { + data_m <- melt(data, id.vars=ID_var) + } else { + data_m <- melt(data) + } + } + } +} else { + data_m <- read.table(file="boxplot.melt.data", sep="\t", + header=TRUE, quote="") +} + + +if (0 != 0){ + data_m$Expr <- data_m$Expr + 0 +} + +level <- c() + + +if ("" != "") { + data_m$Group <- cut(data_m$Group, ) +} else if (length(level)>1){ + level_i <- level + data_m$Group <- factor(data_m$Group, levels=level_i) +} + +x_level <- c() + +if ("" != "") { + data_m$Group <- cut(data_m$Group,) +}else if (length(x_level)){ + data_m$Group <- factor(data_m$Group,levels=x_level) +} + + +facet_level <- c(NA) +if (length(facet_level)>1) { + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s, + levels=facet_level, ordered=T) +} + +### add by lindechun +if ("Group" == "Group") { + dat <- s_boxplot_median(data_m, more_v=FALSE) +}else{ + dat <- s_boxplot_median(data_m, more_v=TRUE) +} + +data_m <- dat$data_m + +## calculate point size of jitter +data_nrow=nrow(dat$data_m) +if (data_nrow < 50) { + jitter_size=1 +}else{ + jitter_size=0.5 +} + +dat$data_m$Group <- factor(data_m$Group) +dat$data_m$Group <- factor(data_m$Group) + +data_m$Group <- factor(data_m$Group) +data_m$Group <- factor(data_m$Group) + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s") { + dat$data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s) + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s) +} + + +### add by lindechun + +p <- ggplot(dat$data_m, aes(Group, Expr)) + xlab("Group") + + ylab("Expr") + labs(title="") + +if (FALSE) { + p <- p + geom_violin(aes(color=Group,fill=Group), + stat = "ydensity", position = "dodge", trim = TRUE, + scale = "width") + + if ("Group" != "Group") { + p <- p + geom_point(data=dat$data_bp_median,aes(x=a3,y=median), size=1)+ + coord_cartesian(ylim=c(min(dat$data_m_temp$Expr),max(dat$data_m_temp$Expr))) + }else{ + p <- p+geom_point(data=dat$data_bp_median,aes(x=Group, y=median),size=1) + } + + # stat_summary(aes(group=Group), fun.y=mean, + # geom="point", fill="black", shape=19, size=1, + # position = position_dodge(width = .9)) + +} else if (TRUE) { + p <- p + geom_violin(aes(color=Group),size=0.5, + stat = "ydensity", position = "dodge", trim = TRUE, + scale = "width")+geom_quasirandom(size=jitter_size) + + if ("Group" != "Group") { + p <- p + geom_point(data=dat$data_bp_median,aes(x=a3,y=median), size=1.5, shape=17)+ + coord_cartesian(ylim=c(min(dat$data_m_temp$Expr),max(dat$data_m_temp$Expr))) + }else{ + p <- p+geom_point(data=dat$data_bp_median,aes(x=Group,y=median), size=1.5, shape=17) + } + +} else if (FALSE) { + + p <- p + geom_quasirandom(aes(color=Group),size=jitter_size) + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 5, color= "black") +} else { + if (FALSE){ + if (FALSE){ + p <- p + geom_boxplot(aes(fill=Group,color=Group), notch=TRUE,width=0.75, + notchwidth=0.3, outlier.colour='NA') + }else{ + p <- p + geom_boxplot(aes(fill=Group,color=Group), notch=TRUE,outlier.size=0.5, width=0.75, + notchwidth=0.3) + } + } else { + if (FALSE){ + p <- p + geom_boxplot(aes(fill=Group,color=Group), + outlier.colour='NA', width=0.75) + }else{ + p <- p + geom_boxplot(aes(fill=Group,color=Group),outlier.size=0.5, width=0.75) + } + } + if ("Group" != "Group") { + p <- p + geom_crossbar(data=dat$data_bp_median,aes(x=a3,y=median,ymin=median,ymax=median),width=0.8*0.75/length(unique(dat$data_m_temp$a2)),fatten=0,size=0.7,color="white")+ + coord_cartesian(ylim=c(min(dat$data_m_temp$Expr),max(dat$data_m_temp$Expr))) + } else { + p <- p + geom_crossbar(data=dat$data_bp_median,aes(x=Group,y=median,ymax=median,ymin=median),width=0.75,color="white",fatten=0,size=0.7) + } +} + +if (FALSE) { + p <- p + geom_quasirandom(color="black",size=jitter_size) +} + + +if (FALSE) { + p <- p + scale_y_log10() + # p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 5, color= "black") +} + +if (FALSE) { + #ylim_zoomin <- boxplot.stats(dat$data_m$Expr)$stats[c(1,5)] + stats <- boxplot.stats(dat$data_m$Expr)$stats + ylim_zoomin <- c(stats[1]/1.05, stats[5]*1.05) + p <- p + coord_cartesian(ylim = ylim_zoomin) +} + + +if (FALSE) { + p <- p + scale_fill_manual(values=c())+scale_colour_manual(values=c()) +} + +if (FALSE) { + p <- p + coord_flip() +} + + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s") { + # p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s, nrow=NULL, ncol=NULL,scale="fixed") + p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s,scale="fixed") +} + + +#Configure the canvas + +p <- p + theme_classic2() + +#Correcting location of x-aixs label +p <- Xlable_angle_correct(p, 0) + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- right + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p + +# output pictures +w_auto_temp=length(levels(data_m$Group)) + + w_h_auto <- Canvas_size(w_auto_temp, "Group", "Group", FALSE, "right") + w_auto <- w_h_auto[1] + h_auto <- w_h_auto[2] + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s"){ + if ("NULL" != 'NULL') { + h_auto=h_auto*NULL + } + if ("NULL" != 'NULL') { + w_auto=w_auto*NULL + } + if ("NULL" == 'NULL' && "NULL" == 'NULL'){ + w_auto=w_auto*3 + h_auto=h_auto*0.7*length(levels(data_m$NoMeAnInGTh_I_n_G_s))/3 + } +} + + +# Control margin of plot by exist status of title, xlab, ylab +if ("" == "") { + p <- p+ theme(plot.title=element_blank()) +} +if ("Group" == "") { + p <- p+ theme(axis.title.x=element_blank()) +} +if ("Expr" == "") { + p <- p+ theme(axis.title.y=element_blank()) +} + +## savefig +if ("" != ''){ + if (!FALSE){ + Savefig("boxplot.melt.data.Expr_Group_Group.violin_jitter.pdf", p, , , "300", "pdf") + }else{ + Savefig("boxplot.melt.data.Expr_Group_Group.violin_jitter.pdf", p, , , "300", "pdf") + } +}else{ + if (!FALSE){ + Savefig("boxplot.melt.data.Expr_Group_Group.violin_jitter.pdf", p, w_auto, h_auto, "300", "pdf") + }else{ + Savefig("boxplot.melt.data.Expr_Group_Group.violin_jitter.pdf", p, h_auto, w_auto, "300", "pdf") + } +} diff --git a/example/boxplot/boxplot.melt.data.boxplot.Expr_Group.facet_wrap.pdf b/example/boxplot/boxplot.melt.data.boxplot.Expr_Group.facet_wrap.pdf new file mode 100644 index 0000000..1269547 Binary files /dev/null and b/example/boxplot/boxplot.melt.data.boxplot.Expr_Group.facet_wrap.pdf differ diff --git a/example/boxplot/boxplot.melt.data.boxplot.Expr_Group_Rep.pdf b/example/boxplot/boxplot.melt.data.boxplot.Expr_Group_Rep.pdf new file mode 100644 index 0000000..c543988 Binary files /dev/null and b/example/boxplot/boxplot.melt.data.boxplot.Expr_Group_Rep.pdf differ diff --git a/example/boxplot/boxplot.melt.data_temp b/example/boxplot/boxplot.melt.data_temp new file mode 100644 index 0000000..69934ff --- /dev/null +++ b/example/boxplot/boxplot.melt.data_temp @@ -0,0 +1,127 @@ +Gene Sample Group Expr Rep +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +A zygote_1 zygote 0.8 1 +A zygote_2 zygote 1.3 2 +A zygote_3 zygote 1.4 3 +A zygote_4 zygote 0.9 4 +A zygote_5 zygote 1.9 5 +A zygote_6 zygote 1.2 6 +A 2cell_1 2cell 8.0 1 +A 2cell_2 2cell 13.0 2 +A 2cell_3 2cell 14.0 3 +A 2cell_4 2cell 9.0 4 +A 2cell_5 2cell 19.0 5 +A 2cell_6 2cell 12.0 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 diff --git a/example/boxplot/boxplot.normal.data b/example/boxplot/boxplot.normal.data new file mode 100644 index 0000000..336118e --- /dev/null +++ b/example/boxplot/boxplot.normal.data @@ -0,0 +1,10 @@ +Name 2cell_1 2cell_2 2cell_3 2cell_4 2cell_5 2cell_6 4cell_1 4cell_2 4cell_3 4cell_4 4cell_5 4cell_6 zygote_1 zygote_2 zygote_3 zygote_4 zygote_5 zygote_6 +A 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +B 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +C 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +D 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +E 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +F 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +G 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +H 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 +I 8 13 14 9 19 12 3.2 5.2 5.6 3.6 7.6 4.8 0.8 1.3 1.4 0.9 1.9 1.2 diff --git a/example/boxplot/boxplot.normal.data.A_Group.violin.pdf b/example/boxplot/boxplot.normal.data.A_Group.violin.pdf new file mode 100644 index 0000000..d549c3a Binary files /dev/null and b/example/boxplot/boxplot.normal.data.A_Group.violin.pdf differ diff --git a/example/boxplot/boxplot.normal.data.violin.pdf b/example/boxplot/boxplot.normal.data.violin.pdf new file mode 100644 index 0000000..fcf365b Binary files /dev/null and b/example/boxplot/boxplot.normal.data.violin.pdf differ diff --git a/example/boxplot/example.sh b/example/boxplot/example.sh new file mode 100755 index 0000000..0938859 --- /dev/null +++ b/example/boxplot/example.sh @@ -0,0 +1,25 @@ +#使用说明: + ## 外层引号与内层引号不能相同 + ## 凡参数值中包括了空格,括号,逗号等都用引号括起来作为一个整体 + ##程序自动计算图形长宽 + +# 实例: +## 绘制每个样品的表达矩阵 +s-plot boxplot -f boxplot.normal.data -P none -b 45 -V TRUE + +## 绘制单个基因的小提琴图加抖动图(设定坐标标签顺序,图例颜色) +s-plot boxplot -f boxplot.normal.data -q A -Q sampleGroup -a Group -V TRUE -L "'zygote','2cell','4cell'" -c TRUE -C "'red', 'pink', 'blue'" -x A_sample -y expr + +## 使用melted矩阵默认参数绘制小提琴图+扰动图 +s-plot boxplot -f boxplot.melt.data -m TRUE -d Expr -a Group -W TRUE +## 扰动图 +s-plot boxplot -f boxplot.melt.data -m TRUE -d Expr -a Group -j TRUE + +# 使用主题 +s-plot boxplot -f boxplot.melt.data -m TRUE -d Expr -F Rep -a Group -T theme_cin + +## 旋转坐标轴 +s-plot boxplot -f boxplot.melt.data -m TRUE -d Expr -a Group -J TRUE -R TRUE + +##分面 +s-plot boxplot -f boxplot.melt.data -m TRUE -d Expr -a Group -b 45 -G Rep -M 2 -N 2 diff --git a/example/boxplot/modify.md b/example/boxplot/modify.md new file mode 100644 index 0000000..102c77e --- /dev/null +++ b/example/boxplot/modify.md @@ -0,0 +1,32 @@ +1. s-plot boxplot -f boxplot.normal.data -P none -b 45 -q A +> 此图每个box都只有一个点,对于这种情况,设定了-q 但没设定-Q,导致每个x轴标签只有一个数据点,脚本会运行并出图,但会提示推荐用line或point脚本画图 + +2. -F(图例) 和 -a(x轴) 的逻辑调整了,-F不设,默认使用-a,为每个label的数据填充颜色 + + +3. 如果-m TRUE, 且 -x 和 -y 未设,则用-a 和 -d 指定名称分别作为坐标轴名称 + +4. 增加-K width_box,默认0.75(小提琴图,箱线图宽度) + +5. 增加主题风格的选择:默认:theme_classic2 + +6. 图形长宽根据数据情况自动调整 + +7. -m TRUE 若设定,未设-a,程序报错退出 + +8. 扰动图的点的大小,根据输入样本的数值范围设定大小 + +9. 箱线图fill和color标度均对应同一个变量,中位线用白色,outlier的点大小设小一点 + +10. x坐标轴45度,标签对齐 + +11. 新增 <保存图形>,<计算输出图形长宽>, 等函数,可供线,点,条形图等使用 + +11. 组合图的逻辑: + + * 默认箱线图 + * 扰动图、小提琴图、箱线图三选一 + * 组合图:箱线图+扰动图,小提琴图+扰动图 + + +12. x坐标标签对应的数据未涵盖所有legend元素,缺失的值处理,让median线长度位置与图形相对应(不考虑扰动图) \ No newline at end of file diff --git a/example/boxplot/sampleGroup b/example/boxplot/sampleGroup new file mode 100644 index 0000000..4852a71 --- /dev/null +++ b/example/boxplot/sampleGroup @@ -0,0 +1,19 @@ +Sample Group +zygote_1 zygote +zygote_2 zygote +zygote_3 zygote +zygote_4 zygote +zygote_5 zygote +zygote_6 zygote +2cell_1 2cell +2cell_2 2cell +2cell_3 2cell +2cell_4 2cell +2cell_5 2cell +2cell_6 2cell +4cell_1 4cell +4cell_2 4cell +4cell_3 4cell +4cell_4 4cell +4cell_5 4cell +4cell_6 4cell diff --git a/example/boxplot_precomputed_values/Set.boxplot.r b/example/boxplot_precomputed_values/Set.boxplot.r new file mode 100644 index 0000000..f754fb2 --- /dev/null +++ b/example/boxplot_precomputed_values/Set.boxplot.r @@ -0,0 +1,126 @@ + +if (FALSE){ + install.packages("ggplot2", repo="http://cran.us.r-project.org") + install.packages("reshape2", repo="http://cran.us.r-project.org") + install.packages("scales", repo="http://cran.us.r-project.org") + if(FALSE){ + install.packages("ggbeeswarm", repo="http://cran.us.r-project.org") + } +} + +if(FALSE){ + library(ggbeeswarm) +}else if(FALSE){ + library(ggbeeswarm) +} + +library(ggplot2) +library(reshape2) +library(scales) + +data_m <- read.table(file="Set", sep="\t", header=TRUE, +row.names=NULL, quote="") + +if ("" != ""){ + data_m$variable <- cut(data_m$variable, ) +} else if ("" != ""){ + level_i <- c() + data_m$variable <- factor(data_m$variable, levels=level_i) +} +if ("" != ""){ + data_m$variable <- cut(data_m$variable,) +}else if ("" != ""){ + x_level <- c() + data_m$variable <- factor(data_m$variable,levels=x_level) +} + +if ("NA" != "NA") { + facet_level <- c(NA) + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s, + levels=facet_level, ordered=T) +} + + +#Samp minimum maximum lower_quantile median upper_quantile Set +p <- ggplot(data_m, aes(x=factor(variable), ymin=minimum, lower=lower_quantile, + middle=median, upper=upper_quantile, ymax=maximum)) + + xlab(" ") + ylab(" ") + labs(title="") + + +if (TRUE){ + p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, + notchwidth=0.3, stat = "identity") +}else { + p <- p + geom_boxplot(aes(fill=factor(variable)), stat = "identity") +} + + +if(FALSE){ + p <- p + scale_y_log10() + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") +} + + +if(FALSE){ + p <- p + scale_fill_manual(values=c()) +} + +if(FALSE){ + p <- p + coord_flip() +} + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s"){ + p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s, nrow=NULL, ncol=NULL, + scale="fixed") +} + + + +#Configure the canvas +#legend.title=element_blank(), +p <- p + theme_bw() + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + legend.key=element_blank()) + +if (0 != 0){ + if (0 == 90){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=1, vjust=0.5)) + }else if (0 == 45){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } else { + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } +} + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- right + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p + + +# output pictures + +if ("pdf" == "pdf") { + ggsave(p, filename="Set.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm"),colormodel="srgb") +} else { + ggsave(p, filename="Set.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm")) +} +#png(filename="Set.boxplot.png", width=20, height=12, +#res=300) +#p +#dev.off() diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values b/example/boxplot_precomputed_values/boxplot_precomputed_values new file mode 100644 index 0000000..4011b10 --- /dev/null +++ b/example/boxplot_precomputed_values/boxplot_precomputed_values @@ -0,0 +1,5 @@ +Samp minimum maximum lower_quantile median upper_quantile Set +A 1 10 2 5 7 cl1 +B 1 10 2 5 7 cl2 +C 1 10 2 5 7 cl1 +D 1 10 2 5 7 cl2 diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values-F.boxplot.r b/example/boxplot_precomputed_values/boxplot_precomputed_values-F.boxplot.r new file mode 100644 index 0000000..f3b6cad --- /dev/null +++ b/example/boxplot_precomputed_values/boxplot_precomputed_values-F.boxplot.r @@ -0,0 +1,126 @@ + +if (FALSE){ + install.packages("ggplot2", repo="http://cran.us.r-project.org") + install.packages("reshape2", repo="http://cran.us.r-project.org") + install.packages("scales", repo="http://cran.us.r-project.org") + if(FALSE){ + install.packages("ggbeeswarm", repo="http://cran.us.r-project.org") + } +} + +if(FALSE){ + library(ggbeeswarm) +}else if(FALSE){ + library(ggbeeswarm) +} + +library(ggplot2) +library(reshape2) +library(scales) + +data_m <- read.table(file="boxplot_precomputed_values-F", sep="\t", header=TRUE, +row.names=NULL, quote="") + +if ("" != ""){ + data_m$variable <- cut(data_m$variable, ) +} else if ("" != ""){ + level_i <- c() + data_m$variable <- factor(data_m$variable, levels=level_i) +} +if ("" != ""){ + data_m$variable <- cut(data_m$variable,) +}else if ("" != ""){ + x_level <- c() + data_m$variable <- factor(data_m$variable,levels=x_level) +} + +if ("NA" != "NA") { + facet_level <- c(NA) + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s, + levels=facet_level, ordered=T) +} + + +#Samp minimum maximum lower_quantile median upper_quantile Set +p <- ggplot(data_m, aes(x=factor(variable), ymin=minimum, lower=lower_quantile, + middle=median, upper=upper_quantile, ymax=maximum)) + + xlab(" ") + ylab(" ") + labs(title="") + + +if (TRUE){ + p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, + notchwidth=0.3, stat = "identity") +}else { + p <- p + geom_boxplot(aes(fill=factor(variable)), stat = "identity") +} + + +if(FALSE){ + p <- p + scale_y_log10() + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") +} + + +if(FALSE){ + p <- p + scale_fill_manual(values=c()) +} + +if(FALSE){ + p <- p + coord_flip() +} + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s"){ + p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s, nrow=NULL, ncol=NULL, + scale="fixed") +} + + + +#Configure the canvas +#legend.title=element_blank(), +p <- p + theme_bw() + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + legend.key=element_blank()) + +if (0 != 0){ + if (0 == 90){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=1, vjust=0.5)) + }else if (0 == 45){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } else { + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } +} + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- right + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p + + +# output pictures + +if ("pdf" == "pdf") { + ggsave(p, filename="boxplot_precomputed_values-F.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm"),colormodel="srgb") +} else { + ggsave(p, filename="boxplot_precomputed_values-F.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm")) +} +#png(filename="boxplot_precomputed_values-F.boxplot.png", width=20, height=12, +#res=300) +#p +#dev.off() diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.pdf b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.pdf new file mode 100644 index 0000000..91e5296 Binary files /dev/null and b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.pdf differ diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.r b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.r new file mode 100644 index 0000000..c40b490 --- /dev/null +++ b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.r @@ -0,0 +1,126 @@ + +if (FALSE){ + install.packages("ggplot2", repo="http://cran.us.r-project.org") + install.packages("reshape2", repo="http://cran.us.r-project.org") + install.packages("scales", repo="http://cran.us.r-project.org") + if(FALSE){ + install.packages("ggbeeswarm", repo="http://cran.us.r-project.org") + } +} + +if(FALSE){ + library(ggbeeswarm) +}else if(FALSE){ + library(ggbeeswarm) +} + +library(ggplot2) +library(reshape2) +library(scales) + +data_m <- read.table(file="boxplot_precomputed_values", sep="\t", header=TRUE, +row.names=NULL, quote="") + +if ("" != ""){ + data_m$variable <- cut(data_m$variable, ) +} else if ("" != ""){ + level_i <- c() + data_m$variable <- factor(data_m$variable, levels=level_i) +} +if ("" != ""){ + data_m$Samp <- cut(data_m$Samp,) +}else if ("" != ""){ + x_level <- c() + data_m$Samp <- factor(data_m$Samp,levels=x_level) +} + +if ("NA" != "NA") { + facet_level <- c(NA) + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s, + levels=facet_level, ordered=T) +} + + +#Samp minimum maximum lower_quantile median upper_quantile Set +p <- ggplot(data_m, aes(x=factor(Samp), ymin=minimum, lower=lower_quantile, + middle=median, upper=upper_quantile, ymax=maximum)) + + xlab(" ") + ylab(" ") + labs(title="") + + +if (TRUE){ + p <- p + geom_boxplot(aes(fill=factor(variable)), notch=TRUE, + notchwidth=0.3, stat = "identity") +}else { + p <- p + geom_boxplot(aes(fill=factor(variable)), stat = "identity") +} + + +if(FALSE){ + p <- p + scale_y_log10() + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") +} + + +if(FALSE){ + p <- p + scale_fill_manual(values=c()) +} + +if(FALSE){ + p <- p + coord_flip() +} + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s"){ + p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s, nrow=NULL, ncol=NULL, + scale="fixed") +} + + + +#Configure the canvas +#legend.title=element_blank(), +p <- p + theme_bw() + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + legend.key=element_blank()) + +if (0 != 0){ + if (0 == 90){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=1, vjust=0.5)) + }else if (0 == 45){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } else { + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } +} + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- right + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p + + +# output pictures + +if ("pdf" == "pdf") { + ggsave(p, filename="boxplot_precomputed_values.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm"),colormodel="srgb") +} else { + ggsave(p, filename="boxplot_precomputed_values.boxplot.pdf", dpi=300, width=20, + height=12, units=c("cm")) +} +#png(filename="boxplot_precomputed_values.boxplot.png", width=20, height=12, +#res=300) +#p +#dev.off() diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.pdf b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.pdf new file mode 100644 index 0000000..f32e89e Binary files /dev/null and b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.pdf differ diff --git a/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.r b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.r new file mode 100644 index 0000000..6b44bbd --- /dev/null +++ b/example/boxplot_precomputed_values/boxplot_precomputed_values.boxplot.value_set.r @@ -0,0 +1,126 @@ + +if (FALSE){ + install.packages("ggplot2", repo="http://cran.us.r-project.org") + install.packages("reshape2", repo="http://cran.us.r-project.org") + install.packages("scales", repo="http://cran.us.r-project.org") + if(FALSE){ + install.packages("ggbeeswarm", repo="http://cran.us.r-project.org") + } +} + +if(FALSE){ + library(ggbeeswarm) +}else if(FALSE){ + library(ggbeeswarm) +} + +library(ggplot2) +library(reshape2) +library(scales) + +data_m <- read.table(file="boxplot_precomputed_values", sep="\t", header=TRUE, +row.names=NULL, quote="") + +if ("" != ""){ + data_m$Set <- cut(data_m$Set, ) +} else if ("" != ""){ + level_i <- c() + data_m$Set <- factor(data_m$Set, levels=level_i) +} +if ("" != ""){ + data_m$Set <- cut(data_m$Set,) +}else if ("" != ""){ + x_level <- c() + data_m$Set <- factor(data_m$Set,levels=x_level) +} + +if ("NA" != "NA") { + facet_level <- c(NA) + data_m$NoMeAnInGTh_I_n_G_s <- factor(data_m$NoMeAnInGTh_I_n_G_s, + levels=facet_level, ordered=T) +} + + +#Samp minimum maximum lower_quantile median upper_quantile Set +p <- ggplot(data_m, aes(x=factor(Set), ymin=minimum, lower=lower_quantile, + middle=median, upper=upper_quantile, ymax=maximum)) + + xlab(" ") + ylab(" ") + labs(title="") + + +if (TRUE){ + p <- p + geom_boxplot(aes(fill=factor(Set)), notch=TRUE, + notchwidth=0.3, stat = "identity") +}else { + p <- p + geom_boxplot(aes(fill=factor(Set)), stat = "identity") +} + + +if(FALSE){ + p <- p + scale_y_log10() + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") +} + + +if(FALSE){ + p <- p + scale_fill_manual(values=c()) +} + +if(FALSE){ + p <- p + coord_flip() +} + +if ("NoMeAnInGTh_I_n_G_s" != "NoMeAnInGTh_I_n_G_s"){ + p <- p + facet_wrap( ~ NoMeAnInGTh_I_n_G_s, nrow=NULL, ncol=NULL, + scale="fixed") +} + + + +#Configure the canvas +#legend.title=element_blank(), +p <- p + theme_bw() + theme( + panel.grid.major = element_blank(), + panel.grid.minor = element_blank(), + legend.key=element_blank()) + +if (0 != 0){ + if (0 == 90){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=1, vjust=0.5)) + }else if (0 == 45){ + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } else { + p <- p + theme(axis.text.x= + element_text(angle=0,hjust=0.5, vjust=0.5)) + } +} + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- right + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p + + +# output pictures + +if ("pdf" == "pdf") { + ggsave(p, filename="boxplot_precomputed_values.boxplot.value_Set.pdf", dpi=300, width=20, + height=12, units=c("cm"),colormodel="srgb") +} else { + ggsave(p, filename="boxplot_precomputed_values.boxplot.value_Set.pdf", dpi=300, width=20, + height=12, units=c("cm")) +} +#png(filename="boxplot_precomputed_values.boxplot.value_Set.png", width=20, height=12, +#res=300) +#p +#dev.off() diff --git a/example/boxplot_precomputed_values/err b/example/boxplot_precomputed_values/err new file mode 100644 index 0000000..c5ad4ae --- /dev/null +++ b/example/boxplot_precomputed_values/err @@ -0,0 +1,4 @@ +sh ../../bin/sp_boxplot_precomputed_values.sh -f boxplot_precomputed_values -a Samp +Error in factor(variable) : 找不到对象'variable' +Calls: ggsave ... f -> -> f -> lapply -> FUN -> FUN -> factor +停止执行 diff --git a/example/density2d/density2d b/example/density2d/density2d new file mode 100644 index 0000000..321a2d9 --- /dev/null +++ b/example/density2d/density2d @@ -0,0 +1,7 @@ +Pos gene1 gene2 gene3 gene4 gene5 +time1 1 2000 3000 4000 4000 +time2 1 2000 3000 4000 4000 +time3 1 2000 3000 4000 4000 +time4 1 2000 3000 4000 4000 +time5 1 2000 3000 4000 4000 +time6 1 2000 3000 4000 4000 diff --git a/example/densityHistPlot/densityHistPlot.melt.data b/example/densityHistPlot/densityHistPlot.melt.data new file mode 100644 index 0000000..bf75d98 --- /dev/null +++ b/example/densityHistPlot/densityHistPlot.melt.data @@ -0,0 +1,21 @@ +variable value set(optional) +h3k27ac 8.71298 1 +h3k27ac 8.43246 1 +h3k27ac 8.25497 1 +h3k27ac 7.16265 1 +h3k27ac 3.55341 1 +h3k27ac 3.55030 2 +h3k27ac 7.07502 2 +h3k27ac 8.24328 2 +h3k27ac 8.43869 2 +h3k27ac 8.48877 2 +ctcf 10.69130 1 +ctcf 10.76680 1 +ctcf 10.54410 1 +ctcf 10.86350 1 +ctcf 8.45751 1 +ctcf 8.50316 2 +ctcf 10.91430 2 +ctcf 10.70220 2 +ctcf 10.41010 2 +ctcf 10.57570 2 diff --git a/example/densityHistPlot/densityHistPlot.normal.data b/example/densityHistPlot/densityHistPlot.normal.data new file mode 100644 index 0000000..2c3dfb6 --- /dev/null +++ b/example/densityHistPlot/densityHistPlot.normal.data @@ -0,0 +1,7 @@ +ctcf h3k27ac +1 2 +1 3 +4 2 +1 5 +6 7 +0 10 diff --git a/example/densityPlot/densityPlot.data b/example/densityPlot/densityPlot.data new file mode 100644 index 0000000..00ad79f --- /dev/null +++ b/example/densityPlot/densityPlot.data @@ -0,0 +1,21 @@ +variable value +h3k27ac 8.71298 +h3k27ac 8.43246 +h3k27ac 8.25497 +h3k27ac 7.16265 +h3k27ac 3.55341 +h3k27ac 3.55030 +h3k27ac 7.07502 +h3k27ac 8.24328 +h3k27ac 8.43869 +h3k27ac 8.48877 +ctcf 10.69130 +ctcf 10.76680 +ctcf 10.54410 +ctcf 10.86350 +ctcf 8.45751 +ctcf 8.50316 +ctcf 10.91430 +ctcf 10.70220 +ctcf 10.41010 +ctcf 10.57570 diff --git a/example/hcluster_gg/hcluster_gg.col_anno.data b/example/hcluster_gg/hcluster_gg.col_anno.data new file mode 100644 index 0000000..289ea3e --- /dev/null +++ b/example/hcluster_gg/hcluster_gg.col_anno.data @@ -0,0 +1,6 @@ +Name Sample +T0_1 T0 +T0_2 T0 +T0_3 T0 +T4_1 T4 +T4_2 T4 diff --git a/example/hcluster_gg/hcluster_gg.data b/example/hcluster_gg/hcluster_gg.data new file mode 100644 index 0000000..5bf8e25 --- /dev/null +++ b/example/hcluster_gg/hcluster_gg.data @@ -0,0 +1,10 @@ +Name T0_1 T0_2 T0_3 T4_1 T4_2 +TR19267|c0_g1|CYP703A2 1.431 0.77 1.309 1.247 0.485 +TR19612|c1_g3|CYP707A1 0.72 0.161 0.301 2.457 2.794 +TR60337|c4_g9|CYP707A1 0.056 0.09 0.038 7.643 15.379 +TR19612|c0_g1|CYP707A3 2.011 0.689 1.29 0 0 +TR35761|c0_g1|CYP707A4 1.946 1.575 1.892 1.019 0.999 +TR58054|c0_g2|CYP707A4 12.338 10.016 9.387 0.782 0.563 +TR14082|c7_g4|CYP707A4 10.505 8.709 7.212 4.395 6.103 +TR60509|c0_g1|CYP707A7 3.527 3.348 2.128 3.257 2.338 +TR26914|c0_g1|CYP710A1 1.899 1.54 0.998 0.255 0.427 diff --git a/example/heatmapM/test.2.label b/example/heatmapM/test.2.label new file mode 100644 index 0000000..8422d40 --- /dev/null +++ b/example/heatmapM/test.2.label @@ -0,0 +1,4 @@ +A +B +C +D diff --git a/example/heatmapM/test.2.overlap b/example/heatmapM/test.2.overlap new file mode 100644 index 0000000..e992c24 --- /dev/null +++ b/example/heatmapM/test.2.overlap @@ -0,0 +1,4 @@ +Name a b c a b c a b c a b c +a 1.0 0.6 0.64 1.0 0.75 0.76 1.0 0.67 0.70 1.0 0.70 0.73 +b 0.55 1.0 0.58 0.65 1.0 0.70 0.55 1.0 0.60 0.64 1.0 0.68 +c 0.60 0.59 1.0 0.72 0.76 1.0 0.61 0.63 1.0 0.68 0.69 1.0 diff --git a/example/multibar/data b/example/multibar/data new file mode 100644 index 0000000..8bef67a --- /dev/null +++ b/example/multibar/data @@ -0,0 +1,9 @@ +Gene hmC expr Set +NM_001003918_26622 0 83.1269257376101 1 +NM_001011535_3260 0 0 1 +NM_001012640_14264 0 0 1 +NM_001012640_30427 0 0 1 +NM_001003918_266221 0 0 1 +NM_001017393_30504 0 0 1 +NM_001025241_30464 0 0 1 +NM_001017393_30504 0 0 1 diff --git a/example/pca/pca.normal.data b/example/pca/pca.normal.data new file mode 100644 index 0000000..ee68733 --- /dev/null +++ b/example/pca/pca.normal.data @@ -0,0 +1,6 @@ +ID Samp1 Samp2 Samp3 Samp4 +G1 1000 1000 10000 100 +G2 1000 1000 10000 100 +G3 1000 1000 10000 100 +G4 1000 1000 10000 100 +G5 1000 1000 10000 100 diff --git a/example/pca/sampleGroup b/example/pca/sampleGroup new file mode 100644 index 0000000..bf3c156 --- /dev/null +++ b/example/pca/sampleGroup @@ -0,0 +1,5 @@ +ID type batch condition +Samp1 R a Treat +Samp2 S b Treat +Samp3 S a Control +Samp4 R b Control diff --git a/example/pheatmap/.Rhistory b/example/pheatmap/.Rhistory new file mode 100644 index 0000000..d5d9f73 --- /dev/null +++ b/example/pheatmap/.Rhistory @@ -0,0 +1,512 @@ +stat = "identity" +) +df1 <- data.frame( +x = 1, +y0 = min(y), +y25 = quantile(y, 0.25), +y50 = median(y), +y75 = quantile(y, 0.75), +y100 = max(y) +) +y <- rnorm(100) +df1 <- data.frame( +x = 1, +y0 = min(y), +y25 = quantile(y, 0.25), +y50 = median(y), +y75 = quantile(y, 0.75), +y100 = max(y) +) +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +) +dev.off() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df1, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +) +dev.off() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df1, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +)+theme_classic2() +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1),axis.text=element_text(family="Times",size=14,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 12,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df1, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +)+theme_classic2() +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.border=element_blank(),panel.background=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(2, 2, 1, 1),'cm'),title=element_text(color='black',face='plain',family="Times"), +plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1), +axis.text=element_text(family="Times",size=14,color='black',vjust = 0.1,margin = unit(0.8,"lines")), +legend.background = element_blank(),legend.key=element_rect(color='white',fill='white'),axis.line.x=element_line(size=1,colour="black", linetype='solid'), axis.line.y=element_line(size=1,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1),axis.text=element_text(family="Times",size=14,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=1,colour="black", linetype='solid'), axis.line.y=element_line(size=1,colour="black", linetype='solid'),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1),axis.text=element_text(family="Times",size=14,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1),axis.text=element_text(family="Times",size=14,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=14,vjust = 0.1),axis.text=element_text(family="Times",size=14,color='black',margin = unit(2,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 16,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="d",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="d",y="a",title="c") +dev.off() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=18,vjust = 0.1,hjust = 0),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')), axis.title.x =element_text(size=18,vjust = 0.1),axis.title.y =element_text(size=18,hjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,2,2),'cm')), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +p +p +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times",hjust=0.5),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=16,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times",hjust=0.5),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times",hjust=0.5),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +?theme_bw +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times",hjust=0.5),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=16,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +y <- rnorm(100) +df1 <- data.frame( +x = 1, +y0 = min(y), +y25 = quantile(y, 0.25), +y50 = median(y), +y75 = quantile(y, 0.75), +y100 = max(y) +) +pdf("temp1.pdf",width = 8,height=8) +ggplot(df1, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +)+theme_classic2() +dev.off() +pdf("temp2.pdf",width = 8,height=8) +ggplot(df1, aes(x)) + +geom_boxplot( +aes(ymin = y0, lower = y25, middle = y50, upper = y75, ymax = y100), +stat = "identity" +)+theme_classic3() +dev.off() +theme_zg <- function(..., bg='white'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(), axis.title = element_text(color='black', vjust=0.1), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'), axis.ticks.margin = unit(0.8,"lines"), legend.title=element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')),axis.title = element_text(color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'), axis.ticks.margin = unit(0.8,"lines"),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text.x=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text.x=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',vjust = 0.1,margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')),axis.title = element_text(color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(4,"lines")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'), axis.ticks.margin = unit(0.8,"lines"),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(4,"lines")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'), axis.ticks.margin = unit(0.8,"lines"),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm')),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(4,"lines")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(4,unit="cm")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(10,unit="cm")), axis.ticks.length = unit(-0.4,"lines"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +dev.off() +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(10,unit="cm")), axis.ticks.length = unit(-0.4,"cm"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(-10,unit="cm")), axis.ticks.length = unit(-0.4,"cm"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(20,unit="cm")), axis.ticks.length = unit(-0.4,"cm"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme(axis.ticks.length = unit(0.3,"cm", axis.text.x = element_text(margin = margin(0.2, unit = "cm"))) +theme(axis.ticks.length = unit(0.3,"cm", axis.text.x = element_text(margin = margin(0.2, unit = "cm")))) +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(20,unit="cm")), axis.ticks.length = unit(0.4,"cm"), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"cm"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(2,"cm")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"cm"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(5,"cm")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"cm"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(5,unit="cm")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(5,"lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +pdf("temp1.pdf",width = 8,height=8) +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +dev.off() +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(8,"lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(30,"lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +?unit +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = unit(1,"lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(3,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = margin(0.8,unit="lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(0.8,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin((t=0,r=2,b=0,l=0),unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin((t=0,r=2,b=0,l=0),unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(t=0,r=2,b=0,l=0)), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(t=2,r=2,b=2,l=2)), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text.y=element_text(family="Times",size=16,color='black',margin = margin(t=2,r=2,b=2,l=2)), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(t=2,r=2,b=2,l=2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_classic2 <- function(...) { +theme_bw()+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 14,color = 'black',family = 'Times', hjust = 0)) +} +theme_classic3 <- function(...) { +theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=16,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=14,color = 'black',family = 'Times', hjust = 0)) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic3() +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_classic2() +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+ +theme_classic() + +theme(axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank())+labs(x="dwdwdefde",y="a",title="c") +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+ +theme(axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank())+labs(x="dwdwdefde",y="a",title="c") +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+ theme_classic() +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme(axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank())+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_classic(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +theme_zg <- function(..., bg='transparent'){ +require(grid) +theme_bw(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 18,margin=unit(c(2,2,0.5,1),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.2,"lines"),axis.text=element_text(family="Times",size=16,color='black',margin = margin(0.2,unit="lines")), axis.ticks = element_line(color='black'),legend.background = element_blank(), legend.key=element_rect(fill='transparent', color='transparent')) +} +ggplot(df, aes(xmin = x - w / 2, xmax = x + w / 2, ymin = y, ymax = y + 1)) +geom_rect(aes(fill = z, width = w), colour = "grey50")+theme_zg()+labs(x="dwdwdefde",y="a",title="c") +setwd("/opt/bin/s-plot/demo/pheatmap") +source('/opt/bin/s-plot/bin/rFunction.R') +if (TRUE){ +installp("pheatmap",force = F) +# install.packages("pheatmap", repo="http://cran.us.r-project.org") +} +library(grid) +library(pheatmap) +if(1){ +library(RColorBrewer) +} +find_coordinates = function(n, gaps, m=1:n) { +if(length(gaps)==0){ +return(list(coord=unit(m/n, "npc"), size=unit(1/n,"npc"))) +} +if(max(gaps)>n){ +stop("Gaps do not match matrix size") +} +size = (1/n)*(unit(1, "npc")-length(gaps)*unit("4", "bigpts")) +gaps2 = apply(sapply(gaps, function(gap, x){x>gap}, m), 1, sum) +coord = m * size + (gaps2 * unit("4", "bigpts")) +return(list(coord=coord, size=size)) +} +vjust <- 0 +hjust <- 0.5 +if(270==270){ +vjust <- 0.5 +hjust <- 0 +}else if(270==45){ +vjust <- .5 +hjust <- 1 +}else if(270==0){ +vjust <- 1 +hjust <- 0.5 +} +draw_colnames_custom <- function (coln, gaps, ...){ +coord = find_coordinates(length(coln), gaps) +x = coord$coord - 0.5 * coord$size +if (270 == 90){ +hjust = 1 +vjust = 0.5 +} +if (270 == 45){ +hjust = 1 +vjust = 0.5 +} +res = textGrob(coln, x=x, y=unit(1, "npc")-unit(3, "bigpts"), +vjust = vjust, hjust=hjust, rot=270, gp=gpar(...)) +return(res) +} +vjust <- 0 +hjust <- 0.5 +if(270==270){ +vjust <- 0.5 +hjust <- 0 +}else if(270==45){ +vjust <- .5 +hjust <- 1 +}else if(270==0){ +vjust <- 1 +hjust <- 0.5 +} +draw_colnames_custom <- function (coln, gaps, ...){ +coord = find_coordinates(length(coln), gaps) +x = coord$coord - 0.5 * coord$size +if (270 == 90){ +hjust = 1 +vjust = 0.5 +} +if (270 == 45){ +hjust = 1 +vjust = 0.5 +} +res = textGrob(coln, x=x, y=unit(1, "npc")-unit(3, "bigpts"), +vjust = vjust, hjust=hjust, rot=270, gp=gpar(...)) +return(res) +} +?assignInNamespace +assignInNamespace(x="draw_colnames", value="draw_colnames_custom", +ns=asNamespace("pheatmap")) +draw_colnames_custom() +draw_colnames_custom +data <- read.table(file="heatmap_data.xls", sep="\t", header=T, row.names=1, +check.names=F, quote="", comment="") +?read.table +FALSE(1+1) +data +data+1 +data[data==0] +data[data==1] +data[data==1.998] +data==1.998 +log2(data+1) +if ("FALSE" != "FALSE"){ +#data[data==0] <- 1.0000001 +#data[data==1] <- 1.0001 +data <- FALSE(data+1) +} +prettyNum(c(1,2,3)) +?prettyNum +c(t(data)) +t(data) +data +?pheatmap diff --git a/example/pheatmap/example.sh b/example/pheatmap/example.sh new file mode 100755 index 0000000..72cfbd6 --- /dev/null +++ b/example/pheatmap/example.sh @@ -0,0 +1,2 @@ +s-plot pheatmap -f heatmap_data.xls -d row -P heatmap_row_anno.xls -Q heatmap_col_anno.xls -o ./ -A 45 -e FALSE +Rscript heatmap_data.xls.pheatmap.r diff --git a/example/pheatmap/heatmap_col_anno.xls b/example/pheatmap/heatmap_col_anno.xls new file mode 100644 index 0000000..289ea3e --- /dev/null +++ b/example/pheatmap/heatmap_col_anno.xls @@ -0,0 +1,6 @@ +Name Sample +T0_1 T0 +T0_2 T0 +T0_3 T0 +T4_1 T4 +T4_2 T4 diff --git a/example/pheatmap/heatmap_data.xls b/example/pheatmap/heatmap_data.xls new file mode 100644 index 0000000..6e73827 --- /dev/null +++ b/example/pheatmap/heatmap_data.xls @@ -0,0 +1,11 @@ +Name T0_1 T0_2 T0_3 T4_1 T4_2 +TR19267|c0_g1|CYP703A2 1.431 0.77 1.309 1.247 0.485 +TR19612|c1_g3|CYP707A1 0.72 0.161 0.301 2.457 2.794 +TR60337|c4_g9|CYP707A1 0.056 0.09 0.038 7.643 15.379 +TR19612|c0_g1|CYP707A3 2.011 0.689 1.29 0 0 +TR35761|c0_g1|CYP707A4 1.946 1.575 1.892 1.019 0.999 +TR58054|c0_g2|CYP707A4 12.338 10.016 9.387 0.782 0.563 +TR14082|c7_g4|CYP707A4 10.505 8.709 7.212 4.395 6.103 +TR60509|c0_g1|CYP707A7 3.527 3.348 2.128 3.257 2.338 +TR26914|c0_g1|CYP710A1 1.899 1.54 0.998 0.255 0.427 + diff --git a/example/pheatmap/heatmap_data.xls.pheatmap.pdf b/example/pheatmap/heatmap_data.xls.pheatmap.pdf new file mode 100644 index 0000000..54727e2 Binary files /dev/null and b/example/pheatmap/heatmap_data.xls.pheatmap.pdf differ diff --git a/example/pheatmap/heatmap_data.xls.pheatmap.r b/example/pheatmap/heatmap_data.xls.pheatmap.r new file mode 100644 index 0000000..10f304a --- /dev/null +++ b/example/pheatmap/heatmap_data.xls.pheatmap.r @@ -0,0 +1,196 @@ +source('/opt/bin/s-plot/rFunction.R') + +if (FALSE){ + installp("pheatmap",force = F) + # install.packages("pheatmap", repo="http://cran.us.r-project.org") +} + +library(grid) +library(pheatmap) + +if(1){ + library(RColorBrewer) +} + +#draw_colnames_custom <- function (coln, ...){ +# m = length(coln) +# x = (1:m)/m - 1/2/m +# grid.text(coln, x=x, y=unit(0.96, "npc"), vjust=.5, hjust=1, +# rot=45, gp=gpar(...)) +#} +# +# +##Ref:http://stackoverflow.com/questions/15505607/diagonal-labels-orientation-on-x-axis-in-heatmaps + + +# Get the function to edit trace(pheatmap:::draw_colnames, edit=TRUE) +# in R console + +find_coordinates = function(n, gaps, m=1:n) { + if(length(gaps)==0){ + return(list(coord=unit(m/n, "npc"), size=unit(1/n,"npc"))) + } + + if(max(gaps)>n){ + stop("Gaps do not match matrix size") + } + + size = (1/n)*(unit(1, "npc")-length(gaps)*unit("4", "bigpts")) + + gaps2 = apply(sapply(gaps, function(gap, x){x>gap}, m), 1, sum) + coord = m * size + (gaps2 * unit("4", "bigpts")) + + return(list(coord=coord, size=size)) +} + + +vjust <- 0 +hjust <- 0.5 + +if(45==270){ + vjust <- 0.5 + hjust <- 0 +}else if(45==45){ + vjust <- .5 + hjust <- 1 +}else if(45==0){ + vjust <- 1 + hjust <- 0.5 +} + + + +draw_colnames_custom <- function (coln, gaps, ...){ + coord = find_coordinates(length(coln), gaps) + x = coord$coord - 0.5 * coord$size + if (45 == 90){ + hjust = 1 + vjust = 0.5 + } + if (45 == 45){ + hjust = 1 + vjust = 0.5 + } + + res = textGrob(coln, x=x, y=unit(1, "npc")-unit(3, "bigpts"), + vjust = vjust, hjust=hjust, rot=45, gp=gpar(...)) + return(res) +} + + +# Overwrite default draw_colnames with your own version +assignInNamespace(x="draw_colnames", value="draw_colnames_custom", + ns=asNamespace("pheatmap")) + +data <- read.table(file="heatmap_data.xls", sep="\t", header=T, row.names=1, + check.names=F, quote="", comment="") + +if ("FALSE" != "FALSE"){ + #data[data==0] <- 1.0000001 + #data[data==1] <- 1.0001 + data <- FALSE(data+1) +} + +if (1 == 1){ + legend_breaks = NA +} else if (1 == 2){ + if (Inf == Inf){ + summary_v <- c(t(data)) + legend_breaks <- unique(c(seq(summary_v[1]*0.95,summary_v[2],length=6), + seq(summary_v[2],summary_v[3],length=6), + seq(summary_v[3],summary_v[5],length=5), + seq(summary_v[5],summary_v[6]*1.05,length=5))) + } else { + legend_breaks <- unique(c(seq(summary_v[1]*0.95, Inf, + length=10), seq(Inf,summary_v[6]*1.05,length=10))) + } + + if("FALSE" != "FALSE"){ + legend_breaks <- prettyNum(legend_breaks, digits=FALSE) + } + + print(col) + print(legend_breaks) +} else { + legend_breaks <- c() +} + + +if ("heatmap_row_anno.xls" != "NA") { + annotation_row <- read.table(file="heatmap_row_anno.xls", header=T, + row.names=1, sep="\t", quote="", check.names=F, comment="") +} else { + annotation_row <- NA +} + +if ("heatmap_col_anno.xls" != "NA") { + annotation_col <- read.table(file="heatmap_col_anno.xls", header=T, + row.names=1, sep="\t", quote="", check.names=F, comment="") + # Do not remember what this is for? + #levs <- unique(unlist(lapply(annotation_col, unique))) + #annotation_col <- data.frame(lapply(annotation_col, factor, + # levels=levs), row.names=rownames(annotation_col)) +} else { + annotation_col <- NA +} + +data[data>Inf] <- Inf +if ("-Inf" != "-Inf"){ + data[data<-Inf] <- -Inf +} + +if ("function" == "function"){ + color_vector <- colorRampPalette(rev(brewer.pal(n=7, name="RdYlBu")))(100) +} else if ("function" == "vector"){ + colfunc <- colorRampPalette(colorRampPalette(rev(brewer.pal(n=7, name="RdYlBu")))(100), bias=1) + color_vector <- colfunc(30) +} else { + color_vector <- colorRampPalette(rev(brewer.pal(n=7, name="RdYlBu")))(100) +} + +### control width and height add by lin dechun + +if (!is.numeric(FALSE)) { + if ("heatmap_row_anno.xls" != "NA" || "heatmap_col_anno.xls" != "NA") { + temp1=ncol(data)+max(sapply(rownames(data),nchar))/10+4 + } else { + temp1=ncol(data)+max(sapply(rownames(data),nchar))/10+2 + } + + temp2=nrow(data)+max(sapply(colnames(data),nchar))/10 + + if (temp1 > temp2){ + temp2=temp2*(8/temp1) + temp1=8 + } else{ + temp1=temp1*(8/temp2) + temp2=8 + } + + pheatmap(data, kmean_k=NA, color=color_vector, + scale="row", border_color=NA, + cluster_rows=TRUE, cluster_cols=FALSE, + breaks=legend_breaks, clustering_method="complete", + clustering_distance_rows="correlation", + clustering_distance_cols="correlation", + legend_breaks=legend_breaks, show_rownames=TRUE, show_colnames=TRUE, + main="", annotation_col=annotation_col, + annotation_row=annotation_row, + fontsize=14, filename=".//heatmap_data.xls.pheatmap.pdf", width=temp1, + height=temp2) +}else{ + pheatmap(data, kmean_k=NA, color=color_vector, + scale="row", border_color=NA, + cluster_rows=TRUE, cluster_cols=FALSE, + breaks=legend_breaks, clustering_method="complete", + clustering_distance_rows="correlation", + clustering_distance_cols="correlation", + legend_breaks=legend_breaks, show_rownames=TRUE, show_colnames=TRUE, + main="", annotation_col=annotation_col, + annotation_row=annotation_row, + fontsize=14, filename=".//heatmap_data.xls.pheatmap.pdf", width=FALSE, + height=FALSE) +} + +cat(system("/bin/rm -f Rplots.pdf",intern=TRUE)) + diff --git a/example/pheatmap/heatmap_row_anno.xls b/example/pheatmap/heatmap_row_anno.xls new file mode 100644 index 0000000..7ffcefa --- /dev/null +++ b/example/pheatmap/heatmap_row_anno.xls @@ -0,0 +1,10 @@ +Name Clan Family +TR19267|c0_g1|CYP703A2 CYP71 CYP703 +TR19612|c1_g3|CYP707A1 CYP85 CYP707 +TR60337|c4_g9|CYP707A1 CYP85 CYP707 +TR19612|c0_g1|CYP707A3 CYP85 CYP707 +TR35761|c0_g1|CYP707A4 CYP85 CYP707 +TR58054|c0_g2|CYP707A4 CYP85 CYP707 +TR14082|c7_g4|CYP707A4 CYP85 CYP707 +TR60509|c0_g1|CYP707A7 CYP85 CYP707 +TR26914|c0_g1|CYP710A1 CYP710 CYP710 diff --git a/example/scatterplot3d/pca.normal.data b/example/scatterplot3d/pca.normal.data new file mode 100644 index 0000000..ee68733 --- /dev/null +++ b/example/scatterplot3d/pca.normal.data @@ -0,0 +1,6 @@ +ID Samp1 Samp2 Samp3 Samp4 +G1 1000 1000 10000 100 +G2 1000 1000 10000 100 +G3 1000 1000 10000 100 +G4 1000 1000 10000 100 +G5 1000 1000 10000 100 diff --git a/example/scatterplot3d/sampleGroup b/example/scatterplot3d/sampleGroup new file mode 100644 index 0000000..bf3c156 --- /dev/null +++ b/example/scatterplot3d/sampleGroup @@ -0,0 +1,5 @@ +ID type batch condition +Samp1 R a Treat +Samp2 S b Treat +Samp3 S a Control +Samp4 R b Control diff --git a/example/scatterplotColor/scatterplotColor.data b/example/scatterplotColor/scatterplotColor.data new file mode 100644 index 0000000..f712da7 --- /dev/null +++ b/example/scatterplotColor/scatterplotColor.data @@ -0,0 +1,10 @@ +Gene hmC Kme Expr Size +1_NM_001001130_23818 0.342364 0.387972 0.562945535966746 expr3 +2_NM_001001144_16662 1.09501 0.927882 10.6244189482162 expr7 +3_NM_001001152_23797 0.14429 0.375741 0 unexpr +4_NM_001001160_10503 0.991374 1.07919 0.0878474532737287 expr1 +5_NM_001001176_17970 0.184586 0.202106 0.9731593253037 expr3 +6_NM_001001177_28078 0.351389 0.411244 0 unexpr +7_NM_001001178_1650 0.328352 0.295332 0.0490132479669711 expr1 +8_NM_001001179_10881 0.693106 0.55201 0 unexpr +9_NM_001001180_13669 0.533143 0.682877 3.73548640439016 expr5 diff --git a/example/scatterplotDoubleVariable/scatterplotDoubleVariable.data b/example/scatterplotDoubleVariable/scatterplotDoubleVariable.data new file mode 100644 index 0000000..aad0485 --- /dev/null +++ b/example/scatterplotDoubleVariable/scatterplotDoubleVariable.data @@ -0,0 +1,19 @@ +Term Sample count p_value +hsa04740:Olfactory transduction b 379 6.48E-13 +hsa04080:Neuroactive ligand-receptor interaction b 256 5.21E-06 +hsa04060:Cytokine-cytokine receptor interaction b 262 8.62E-04 +hsa00830:Retinol metabolism b 54 0.124538325 +hsa04062:Chemokine signaling pathway b 187 0.913682422 +hsa00120:Primary bile acid biosynthesis b 16 0.995946178 +hsa04614:Renin-angiotensin system b 17 0.998465518 +hsa04640:Hematopoietic cell lineage b 86 0.99955116 +hsa04650:Natural killer cell mediated cytotoxicity b 133 0.999599558 +hsa04740:Olfactory transduction a 379 6.48E-13 +hsa04080:Neuroactive ligand-receptor interaction a 256 5.21E-06 +hsa04060:Cytokine-cytokine receptor interaction a 262 8.62E-04 +hsa00830:Retinol metabolism a 54 0.124538325 +hsa04062:Chemokine signaling pathway a 187 0.913682422 +hsa00120:Primary bile acid biosynthesis a 16 0.995946178 +hsa04614:Renin-angiotensin system a 17 0.998465518 +hsa04640:Hematopoietic cell lineage a 86 0.99955116 +hsa04650:Natural killer cell mediated cytotoxicity a 133 0.999599558 diff --git a/example/upsetView/upsetView.data b/example/upsetView/upsetView.data new file mode 100644 index 0000000..ee7036e --- /dev/null +++ b/example/upsetView/upsetView.data @@ -0,0 +1,7 @@ +ID Samp1 Samp2 Samp3 Samp4 Samp5 +G1 1 0 1 0 1 +G2 0 0 1 1 1 +G3 1 1 1 0 1 +G4 1 1 1 0 0 +G5 0 1 0 1 1 +G6 1 0 1 0 0 diff --git a/example/vennDiagram/vennDiagram.data b/example/vennDiagram/vennDiagram.data new file mode 100644 index 0000000..9c4273d --- /dev/null +++ b/example/vennDiagram/vennDiagram.data @@ -0,0 +1,12 @@ +Gene Sample +g1 h3k27ac +g2 h3k27ac +a1 h3k27ac +a3 h3k27ac +b4 h3k27ac +g1 ctcf +h1 ctcf +a3 ctcf +b1 ctcf +b2 ctcf +g2 ctcf diff --git a/example/volcano/volcano.data b/example/volcano/volcano.data new file mode 100644 index 0000000..9ea5e01 --- /dev/null +++ b/example/volcano/volcano.data @@ -0,0 +1,7 @@ +id log2fc -log10(pvalue) significant +1 0 0 1 +1 0 0 1 +3 0 0 1 +1 0 0 0 +2 0 0 0 +1 0 0 0 diff --git a/example/volcano/volcano.data2 b/example/volcano/volcano.data2 new file mode 100644 index 0000000..85bb4d1 --- /dev/null +++ b/example/volcano/volcano.data2 @@ -0,0 +1,7 @@ +id log2fc -log10(pvalue) significant +1 0 0 TRUE +1 0 0 TRUE +3 0 0 TRUE +1 0 0 FALSE +2 0 0 FALSE +1 0 0 FALSE diff --git a/p b/p deleted file mode 100644 index e69de29..0000000 diff --git a/python.log b/python.log deleted file mode 100644 index 93571b0..0000000 --- a/python.log +++ /dev/null @@ -1,4 +0,0 @@ -/home/chentong/home/server/pybin/transferNormalClusteredMatrixForLinePlot.py -i swap - Run time : 2014-09-01 14:15:40 - 2014-09-01 14:15:40 -/home/chentong/home/server/pybin/transferNormalClusteredMatrixForLinePlot.py -i swap s-plot lines - Run time : 2014-09-01 14:20:15 - 2014-09-01 14:20:15 diff --git a/rFunction.R b/rFunction.R new file mode 100644 index 0000000..8eeebd9 --- /dev/null +++ b/rFunction.R @@ -0,0 +1,98 @@ + +## CREATED BY Lin Dechun (lindechun@genomics.cn) + +## install pacakge from Bioconductor +bio <- function(pacakge){ + source("http://bioconductor.org/biocLite.R") + biocLite(pacakge) +} + +## install.package +installp <- function(packagelist,force=F){ + for (package in packagelist){ + if (!package %in% .packages(all.available = T) || force == T){ + install.packages(package,repo="https://mirrors.tuna.tsinghua.edu.cn/CRAN/") + }else{ + print(paste(package," has been installed!",sep="")) + } + } +} + +# themes for ggplot2 self-definited +## axis.title的size大小适用于labs(),而对默认生成的坐标轴标题偏小5左右 +theme_classic2 <- function(...) { + ## 上下左右均有坐标线,主题风格简约 + theme_bw(...)+theme(panel.background=element_rect(color='black'),panel.border=element_rect(fill='transparent',color='black'), panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',family="Times"),plot.title=element_text(size = 19,margin=unit(c(0.5,0.5,0.5,0.5),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=17,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),legend.text=element_text(size = 12,color = 'black',family = 'Times', hjust = 0),legend.title=element_text(size = 13,color = 'black',family = 'Times', hjust = 0)) +} + +theme_classic3 <- function(...) { + ## 左边和下边才有坐标线 + theme_bw(...)+theme(panel.background=element_blank(),panel.border=element_blank(),panel.grid=element_blank(),plot.margin=unit(c(0.5, 0.5, 0.5, 0.5),'cm'),title=element_text(color='black',face='plain',family="Times"),plot.title=element_text(size = 19,margin=unit(c(0.5,0.5,0.5,0.5),'cm'),hjust=0.5), axis.title =element_text(size=18,vjust = 0.1),axis.text=element_text(family="Times",size=17,color='black',margin = unit(0.8,"lines")),legend.background = element_blank(),axis.line.x=element_line(size=0.5,colour="black", linetype='solid'), axis.line.y=element_line(size=0.5,colour="black", linetype='solid'),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0),legend.title=element_text(size = 13,color = 'black',family = 'Times', hjust = 0)) +} + +theme_cin <- function(..., bg='transparent'){ + ## 轴续向内伸 + require(grid) + theme_bw(...) + theme(rect=element_rect(fill=bg), plot.margin=unit(rep(0.5,4), 'lines'), panel.background=element_rect(fill='transparent', color='black'), panel.border=element_rect(fill='transparent', color='transparent'), panel.grid=element_blank(),title=element_text(color='black',face='plain',family="Times"), plot.title=element_text(size = 19,color='black',margin=unit(c(0.5,0.5,0.5,0.5),'cm'),hjust=0.5),axis.title = element_text(size=18,color='black', vjust=0.1), axis.ticks.length = unit(-0.3,"lines"),axis.text.x=element_text(family="Times",size=17,color='black',margin=margin(8,0,3,0,"pt")),axis.text.y=element_text(family="Times",size=17,color='black',margin=margin(0,8,0,3,"pt")), axis.ticks = element_line(color='black'),legend.background = element_blank(),legend.text=element_text(size=12,color = 'black',family = 'Times', hjust = 0),legend.title=element_text(size = 13,color = 'black',family = 'Times', hjust = 0),legend.key=element_rect(fill='transparent', color='transparent')) +} + +# plot tools +## self-correcting location of x-aixs label ( applies to ggplot2) + +Xlable_angle_correct <- function(selfp, xtics_angle) { + + if (xtics_angle != 0){ + if (xtics_angle == 90){ + selfp <- selfp + theme(axis.text.x= + element_text(angle=xtics_angle, hjust=1, vjust=0.5)) + }else if (xtics_angle == 45){ + selfp <- selfp + theme(axis.text.x= + element_text(angle=xtics_angle, hjust=1.1, vjust=1.1)) + } else { + selfp <- selfp + theme(axis.text.x= + element_text(angle=xtics_angle, hjust=0.5, vjust=0.5)) + } + } + return(selfp) + +} + +Canvas_size <- function(w_auto_temp, variable, xvariable, rotate_plot, legend_pos){ + if (w_auto_temp < 8) { + w_auto=w_auto_temp-1 + } else if (w_auto_temp < 20) { + w_auto=8+(w_auto_temp-8)/5 + } else { + w_auto=14+(w_auto_temp-20)/5 + } + + if (variable != xvariable){ + w_auto=w_auto+2 + } + + h_auto=6 + if (! rotate_plot){ + if (legend_pos == "right" || legend_pos == "left"){ + w_auto=w_auto+2 + } + if (legend_pos == "top" || legend_pos == "bottom"){ + h_auto=h_auto+0.5 + w_auto=w_auto+1 + } + }else{ + if (legend_pos == "top" || legend_pos == "bottom"){ + w_auto=w_auto+1 + } + } + return(c(w_auto, h_auto)) +} + +Savefig <- function(filename,plott, width, height, ppi, ftype="pdf"){ + if (ftype == "pdf") { + ggsave(plot=plott, filename=filename, dpi=ppi, width=width, + height=height, units=c("in"),colormodel="srgb") + } else { + ggsave(plot=plott, filename=filename, dpi=ppi, width=width, + height=height, units=c("in")) + } +} diff --git a/s-plot_tutorial.md b/s-plot_tutorial.md new file mode 100644 index 0000000..cec7bd1 --- /dev/null +++ b/s-plot_tutorial.md @@ -0,0 +1,154 @@ +# s_plot的数据格式说明 +--- +## sp_pheatmap.sh +### Matrix file +> heatmap_data.xls + +| Name | T0_1 | T0_2 | T0_3 | T4_1 | T4_2 | +|:-------|:------:|:------:|:------:|:------:|:-----:| +|TR19267|c0_g1|CYP703A2 | 1.431 | 0.77 | 1.309 | 1.247 | 0.485 | +|TR19612|c1_g3|CYP707A1 | 0.72 | 0.161 | 0.301 | 2.457 | 2.794 | +|TR60337|c4_g9|CYP707A1 | 0.056 | 0.09 | 0.038 | 7.643 | 15.379 | +|TR19612|c0_g1|CYP707A3 | 2.011 | 0.689 | 1.29 | 0 | 0 | +|TR35761|c0_g1|CYP707A4 | 1.946 | 1.575 | 1.892 | 1.019 | 0.999 | +|TR58054|c0_g2|CYP707A4 | 12.338 | 10.016 | 9.387 | 0.782 | 0.563 | +|TR14082|c7_g4|CYP707A4 | 10.505 | 8.709 | 7.212 | 4.395 | 6.103 | +|TR60509|c0_g1|CYP707A7 | 3.527 | 3.348 | 2.128 | 3.257 | 2.338 | +|TR26914|c0_g1|CYP710A1 | 1.899 | 1.54 | 0.998 | 0.255 | 0.427 | + + +### Row annorarion file +> heatmap_row_anno.xls + +> 1. At least two columns +> 2. The first column should be the same as the first column in matrix (order does not matter) + +| Name | Clan | Family | +|:------|:------:|:-------:| +| TR19267|c0_g1|CYP703A2 | CYP71 | CYP703| +| TR19612|c1_g3|CYP707A1 | CYP85 | CYP707| +| TR60337|c4_g9|CYP707A1 | CYP85 | CYP707| +| TR19612|c0_g1|CYP707A3 | CYP85 | CYP707| +| TR35761|c0_g1|CYP707A4 | CYP85 | CYP707| +| TR58054|c0_g2|CYP707A4 | CYP85 | CYP707| +| TR14082|c7_g4|CYP707A4 | CYP85 | CYP707| +| TR60509|c0_g1|CYP707A7 | CYP85 | CYP707| +| TR26914|c0_g1|CYP710A1 | CYP710 | CYP710| + +### Column annorarion file +> heatmap_col_anno.xls + +> 1. At least two columns +> 2. The first column should be the same as the first row in matrix (order does not matter) + +| Name | Sample | +|:------|:------:| +| T0_1 | T0| +| T0_2 | T0| +| T0_3 | T0| +| T4_1 | T4| +| T4_2 | T4| + +## sp_boxplot.sh +> This script is used to do boxplot using ggplot2. + +> For file using "Set" column, you can use boxplot.onefile.sh -f file -a Set + +> fileformat when -m is true + +> Default we use string "value" and "variable" to represent the data + +> column and sub-class column. If you have other strings as column names, please give them to -d and -F. + +> The "Set" column is optional. + +> If you do have several groups, they can put at the "Set" column with "Set" or other string as labels. The label should be given to parameter -a. +> Actually this format is the melted result of last format. + +### Matrix +> fileformat for -f (suitable for data extracted from one sample, the +number of columns is unlimited. Column 'Set' is not necessary unless +you have multiple groups) + +> For file using "Set" column, you can use +boxplot.onefile.sh -f file -a Set + +#### Matrix1 +> boxplot.normal.data + +| Name|2cell_1| 2cell_2 | 2cell_3 | 2cell_4 | 2cell_5 | 2cell_6 | 4cell_1 | 4cell_2 | 4cell_3 | 4cell_4 | 4cell_5 | 4cell_6 | zygote_1 | zygote_2 | zygote_3 | zygote_4 | zygote_5 | zygote_6| +|:--|:---:|:---:|:----:|:---:|:----:|:----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:----:| +|A | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|B | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|C | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|D | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|E | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|F | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|G | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|H | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| +|I | 8 | 13 | 14 | 9 | 19 | 12 | 3.2 | 5.2 | 5.6 | 3.6 | 7.6 | 4.8 | 0.8 | 1.3 | 1.4 | 0.9 | 1.9 | 1.2| + +#### Matrix2 +> boxplot.matrix2.data + +|Gene | hmC | expr | Set| +|:-----|:---:|:--:|:--:| +|NM_001003918_26622 | 0 | 83.1269257376101 | TP16| +|NM_001011535_3260 | 0 | 0 | TP16| +|NM_001012640_14264 | 0 | 0 | TP16| +|NM_001012640_30427 | 0 | 0 | TP16| +|NM_001003918_2662217393_30486 | 0 | 0 | TP16| +|NM_001017393_30504 | 0 | 0 | TP16| +|NM_001025241_30464 | 0 | 0 | TP16| +|NM_001017393_30504001025241_30513 | 0 | 0 | TP16| + +### sampleGroupFile +> sampleGroup + +> 1. TAB separated, first column corresponds to first row of matrix +> 2. Group should be gave to <-F> + +|Sample | G| +|:------|:--:| +|zygote_1 | zygote| +|zygote_2 | zygote| +|zygote_3 | zygote| +|zygote_4 | zygote| +|zygote_5 | zygote| +|zygote_6 | zygote| +|2cell_1 | 2cell| +|2cell_2 | 2cell| +|2cell_3 | 2cell| +|2cell_4 | 2cell| +|2cell_5 | 2cell| +|2cell_6 | 2cell| +|4cell_1 | 4cell| +|4cell_2 | 4cell| +|4cell_3 | 4cell| +|4cell_4 | 4cell| +|4cell_5 | 4cell| +|4cell_6 | 4cell| + +### Matrix_melted +> boxplot.melt.data + +|Gene | Sample | Group | Expr| +|:--- |:------:|:-----:|:---:| +|A | zygote_1 | zygote | 0.8| +|A | zygote_2 | zygote | 1.3| +|A | zygote_3 | zygote | 1.4| +|A | zygote_4 | zygote | 0.9| +|A | zygote_5 | zygote | 1.9| +|A | zygote_6 | zygote | 1.2| +|A | 2cell_1 | 2cell | 8| +|A | 2cell_2 | 2cell | 13| +|A | 2cell_3 | 2cell | 14| +|A | 2cell_4 | 2cell | 9| +|A | 2cell_5 | 2cell | 19| +|A | 2cell_6 | 2cell | 12| +|A | 4cell_1 | 4cell | 3.2| +|A | 4cell_2 | 4cell | 5.2| +|A | 4cell_3 | 4cell | 5.6| +|A | 4cell_4 | 4cell | 3.6| +|A | 4cell_5 | 4cell | 7.6| +|A | 4cell_6 | 4cell | 4.8| \ No newline at end of file diff --git a/shell_test/shell_for_test.sh b/shell_test/shell_for_test.sh new file mode 100644 index 0000000..002bab2 --- /dev/null +++ b/shell_test/shell_for_test.sh @@ -0,0 +1,28 @@ +a=0 +for i in TRUE FALSE TRUE +do + echo $i + ((a++)) +done +echo $a + +violin='FALSE' +violin_jitter='FALSE' +jitter='d' +boxplot_jitter='t' + +b=0 +fo=($violin $violin_jitter $jitter $boxplot_jitter) ##如果字符串有空格,则用引号 + +for i in ${fo[@]} +do + if [ $i != 'FALSE' ];then + echo $i + ((b++)) + fi +done + +if [ $b -gt 1 ];then + echo "You can only choose one of these (-V -W -j -J)" + exit 1 +fi diff --git a/sp_boxplot.sh b/sp_boxplot.sh index f1eb1c4..b528d2a 100755 --- a/sp_boxplot.sh +++ b/sp_boxplot.sh @@ -8,6 +8,8 @@ cat < -Sample Group -zygote_1 zygote -zygote_2 zygote -zygote_3 zygote -zygote_4 zygote -zygote_5 zygote -zygote_6 zygote -2cell_1 2cell -2cell_2 2cell -2cell_3 2cell -2cell_4 2cell -2cell_5 2cell -2cell_6 2cell -4cell_1 4cell -4cell_2 4cell -4cell_3 4cell -4cell_4 4cell -4cell_5 4cell -4cell_6 4cell - -For file using "Set" column, you can use -boxplot.onefile.sh -f file -a Set - -fileformat when -m is true -#Default we use string "value" and "variable" to represent the data -#column and sub-class column. If you have other strings as column -#names, please give them to -d and -F. -#The "Set" column is optional. -#If you do have several groups, they can put at the "Set" column -#with "Set" or other string as labels. The label should be given -#to parameter -a. -#Actually this format is the melted result of last format. - -Matrix_melted - -Gene Sample Group Expr -A zygote_1 zygote 0.8 -A zygote_2 zygote 1.3 -A zygote_3 zygote 1.4 -A zygote_4 zygote 0.9 -A zygote_5 zygote 1.9 -A zygote_6 zygote 1.2 -A 2cell_1 2cell 8 -A 2cell_2 2cell 13 -A 2cell_3 2cell 14 -A 2cell_4 2cell 9 -A 2cell_5 2cell 19 -A 2cell_6 2cell 12 -A 4cell_1 4cell 3.2 -A 4cell_2 4cell 5.2 -A 4cell_3 4cell 5.6 -A 4cell_4 4cell 3.6 -A 4cell_5 4cell 7.6 -A 4cell_6 4cell 4.8 - ${txtbld}OPTIONS${txtrst}: -f Data file (with header line, the first row is the colname, tab seperated. Multiple formats are allowed and described above) @@ -115,11 +30,11 @@ ${txtbld}OPTIONS${txtrst}: ${bldred}[Default "value" represents the column named "value". This parameter can only be set when -m is TRUE.]${txtrst} -F The column represents the variable information, meaning legend_variable. - If no-subclass of X-variavle, this will be treated as X-axis variable. + If no-subclass of X-variavle, this will be used X-axis variable(-a). ${bldred}[Default "variable" represents the column named "variable". This parameter can only be set when -m is TRUE.]${txtrst} -I Other columns you want to treat as ID variable columns except - the one given to -a. Not used when <-m TRUE>. + the one given to -a. Not used when <-m TRUE> or -q be seted. ${bldred}[Default empty string, accept comma separated strings like "'Id1','Id2','Id3'" or single string "id1"]${txtrst} -a Name for x-axis variable @@ -127,8 +42,7 @@ ${txtbld}OPTIONS${txtrst}: for data without 'Set' column. For the given example, 'Group' which represents groups of each gene should be supplied to this parameter. - This parameter can only be set when -m is TRUE. - ${txtrst}] + This parameter must set when -q is not FALSE or -m is TRUE.${txtrst}] -b Rotation angle for x-axis value(anti clockwise) ${bldred}[Default 0]${txtrst} -R Rotate the plot from vertical to horizontal. @@ -166,9 +80,9 @@ ${txtbld}OPTIONS${txtrst}: "c(-1, 0, 1, 2, 5, 10)" will generate (-1,0],(0,1]...(5,10]] -n Using notch (sand clock shape) or not.${txtred}[Default FALSE]${txtrst} -V Do violin plot instead of boxplot.${txtred}[Default FALSE]${txtrst} - -W Do violin plot without inner boxplot.${txtred}[Default FALSE]${txtrst} + -W Do violin plot overlay with jitter.${txtred}[Default FALSE]${txtrst} -j Do jitter plot instead of boxplot.${txtred}[Default FALSE]${txtrst} - -J Do jitter plot overlay with violinplot or boxplot or both.${txtred}[Default FALSE]${txtrst} + -J Do boxplot plot overlay with jitter.${txtred}[Default FALSE]${txtrst} -A The value given to scale for violin plot. if "area", all violins have the same area (before trimming the tails). If "count", areas are scaled proportionally to the number of observations. @@ -181,9 +95,9 @@ ${txtbld}OPTIONS${txtrst}: -g The levels of wrapping to set the order of each group. ${txtred}Normally the unique value of the column given to B in a format like <"'a','b','c','d'">.${txtrst} - -M The number of rows one wants when -G is used.Default NULL. + -M The number of rows one wants when -G is used. Default NULL. ${txtred}[one of -M and -N is enough]${txtrst} - -N The number of columns one wants when -G is used.Default NULL. + -N The number of columns one wants when -G is used. Default NULL. ${txtred}[one of -M and -N is enough]${txtrst} -k Paramter for scales for facet. [${txtred}Optional, only used when -B is given. Default each @@ -192,8 +106,8 @@ ${txtbld}OPTIONS${txtrst}: 'free_x' (variable x ranges for each sub-plot),'free_y' is accepted. ${txtrst}] -t Title of picture[${txtred}Default empty title${txtrst}] - -x xlab of picture[${txtred}Default empty xlab${txtrst}] - -y ylab of picture[${txtred}Default empty ylab${txtrst}] + -x xlab of picture[${txtred}Default name for -a${txtrst}] + -y ylab of picture[${txtred}Default name for -d${txtrst}] -s Scale y axis [${txtred}Default null. Accept TRUE. Also if the supplied number after -S is not 0, this @@ -201,7 +115,7 @@ ${txtbld}OPTIONS${txtrst}: -v If scale is TRUE, give the following scale_y_log10()[default], coord_trans(y="log10"), scale_y_continuous(trans=log2_trans()), coord_trans(y="log2"), - or other legal command for ggplot2)${txtrst}] + or other legal command for ggplot2). should use '***'${txtrst}] -o Exclude outliers. [${txtred}Exclude outliers or not, default FALSE means not.${txtrst}] -O The scales for you want to zoom in to exclude outliers. @@ -221,11 +135,13 @@ ${txtbld}OPTIONS${txtrst}: ${txtrst}] -p [Lowercase p] Other legal R codes for gggplot2 will be given here. [${txtres}Begin with '+' ${txtrst}] - -w The width of output picture.[${txtred}Default 20${txtrst}] - -u The height of output picture.[${txtred}Default 12${txtrst}] + -w The width of output picture.[${txtred}Default auto calculate${txtrst}] + -u The height of output picture.[${txtred}Default auto calculate${txtrst}] + -K The width of sub-box or sub-violin.[${txtred}Default 0.75${txtrst}] -r The resolution of output picture.[${txtred}Default 300 ppi${txtrst}] -E The type of output figures.[${txtred}Default pdf, accept eps/ps, tex (pictex), pdf, jpeg, tiff, bmp, svg and wmf)${txtrst}] + -T The self-definited theme for ggplot2, give the followding theme_classic2 [Default], theme_classic3, theme_cin.${txtrst} -z Is there a header[${bldred}Default TRUE${txtrst}] -e Execute or not[${bldred}Default TRUE${txtrst}] -i Install depeneded packages[${bldred}Default FALSE${txtrst}] @@ -249,11 +165,13 @@ x_cut="" scaleY='FALSE' y_add=0 scaleY_x='scale_y_log10()' +self_theme='theme_classic2' header='TRUE' execute='TRUE' ist='FALSE' -uwid=20 -vhig=12 +uwid='' +vhig='' +sub_box=0.75 res=300 notch='FALSE' par='' @@ -263,11 +181,11 @@ legend_pos='right' color='FALSE' ext='pdf' violin='FALSE' -violin_nb='FALSE' +violin_jitter='FALSE' +jitter='FALSE' +boxplot_jitter='FALSE' scale_violin='width' ID_var="" -jitter='FALSE' -jitter_bp='FALSE' colormodel='srgb' rotate_plot='FALSE' facet='NoMeAnInGTh_I_n_G_s' @@ -278,7 +196,7 @@ facet_level='NA' gene='FALSE' sampleGroup='FALSE' -while getopts "ha:A:b:B:c:C:d:D:e:E:f:F:g:G:M:N:k:i:I:R:j:J:l:L:m:n:o:O:p:P:q:Q:r:s:S:t:u:v:V:w:W:x:y:z:" OPTION +while getopts "ha:A:b:B:c:C:d:D:e:E:f:F:g:G:M:N:k:K:i:I:R:j:J:l:L:m:n:o:O:p:P:q:Q:r:s:S:t:T:u:v:V:w:W:x:y:z:" OPTION do case $OPTION in h) @@ -292,13 +210,13 @@ do melted=$OPTARG ;; a) - xvariable=$OPTARG + variable=$OPTARG ;; d) value=$OPTARG ;; F) - variable=$OPTARG + xvariable=$OPTARG ;; I) ID_var=$OPTARG @@ -307,7 +225,7 @@ do jitter=$OPTARG ;; J) - jitter_bp=$OPTARG + boxplot_jitter=$OPTARG ;; b) xtics_angle=$OPTARG @@ -336,6 +254,9 @@ do t) title=$OPTARG ;; + T) + self_theme=$OPTARG + ;; x) xlab=$OPTARG ;; @@ -361,7 +282,7 @@ do violin=$OPTARG ;; W) - violin_nb=$OPTARG + violin_jitter=$OPTARG ;; A) scale_violin=$OPTARG @@ -411,6 +332,9 @@ do z) header=$OPTARG ;; + K) + sub_box=$OPTARG + ;; e) execute=$OPTARG ;; @@ -429,7 +353,7 @@ if [ -z $file ]; then exit 1 fi -mid='.boxplot' +# mid='.boxplot' if test "${melted}" == "FALSE" && test "${sampleGroup}" == "FALSE"; then if test "${value}" != "value" || test "${variable}" != "variable"; then @@ -440,10 +364,51 @@ files. We will ignore this setting and not affect the result." fi fi -if test "${xvariable}" == ""; then +if test "${melted}" == "FALSE" && test "${gene}" != "FALSE";then + if test "${variable}" == "variable";then + variable="Sample" + fi +fi + +if test "${melted}" == "TRUE" && test "${variable}" == "variable"; then + echo "If '-m TRUE' be set, then -a should be set" + exit 1 +fi + +if test -z "${xvariable}"; then xvariable=${variable} fi +## add by lindechun +if test "${xlab}" == " ";then + xlab=${variable} +fi + +if test "${ylab}" == " ";then + ylab=${value} +fi + +b=0 +plot_judge=($violin $violin_jitter $jitter $boxplot_jitter) + +for i in ${plot_judge[@]} +do + if [ $i != 'FALSE' ];then + ((b++)) + fi +done + +if [ $b -gt 1 ];then + echo "You can only choose one of these (-V -W -j -J)" + exit 1 +fi + +if [ $b -eq 0 ];then + mid=${mid}'.boxplot' +fi + +## add by lindechun + if test "${gene}" != "FALSE"; then value="${gene}" fi @@ -451,11 +416,10 @@ fi if test "${value}" != "value" || test "${variable}" != "variable"; then mid=${mid}'.'${value}_${variable} fi - -#if test "${ID_var}" != ""; then -# ID_var=${ID_var} -#fi +if test "${variable}" != "${xvariable}"; then + mid=${mid}'_'${xvariable} +fi if test "${outlier}" == "TRUE"; then mid=${mid}'.noOutlier' @@ -476,215 +440,390 @@ fi if test "${violin}" == "TRUE"; then mid=${mid}'.violin' fi -if test "${violin_nb}" == "TRUE"; then - mid=${mid}'.violin_nb' + +if test "${violin_jitter}" == "TRUE"; then + mid=${mid}'.violin_jitter' fi if test "${jitter}" == "TRUE"; then mid=${mid}'.jitter' fi -if test "${jitter_bp}" == "TRUE"; then - mid=${mid}'.jitter_bp' +if test "${boxplot_jitter}" == "TRUE"; then + mid=${mid}'.boxplot_jitter' +fi + +if test "${facet}" != "NoMeAnInGTh_I_n_G_s"; then + mid=${mid}'.facet_wrap' fi -. `dirname $0`/sp_configure.sh +function ggplot2_configure { + +cat <>${file}${mid}.r + +#Configure the canvas + +p <- p + ${self_theme}() + +#Correcting location of x-aixs label +p <- Xlable_angle_correct(p, ${xtics_angle}) + +#Set the position of legend +top='top' +botttom='bottom' +left='left' +right='right' +none='none' +legend_pos_par <- ${legend_pos} + +p <- p + theme(legend.position=legend_pos_par) + +#add additional ggplot2 supported commands + +p <- p${par} + +# output pictures +w_auto_temp=length(levels(data_m\$${variable})) + + w_h_auto <- Canvas_size(w_auto_temp, "${variable}", "${xvariable}", ${rotate_plot}, "${legend_pos}") + w_auto <- w_h_auto[1] + h_auto <- w_h_auto[2] + +if ("${facet}" != "NoMeAnInGTh_I_n_G_s"){ + if ("${nrow}" != 'NULL') { + h_auto=h_auto*${nrow} + } + if ("${ncol}" != 'NULL') { + w_auto=w_auto*${ncol} + } + if ("${nrow}" == 'NULL' && "${ncol}" == 'NULL'){ + w_auto=w_auto*3 + h_auto=h_auto*0.7*length(levels(data_m\$${facet}))/3 + } +} + + +# Control margin of plot by exist status of title, xlab, ylab +if ("$title" == "") { + p <- p+ theme(plot.title=element_blank()) +} +if ("$xlab" == "") { + p <- p+ theme(axis.title.x=element_blank()) +} +if ("$ylab" == "") { + p <- p+ theme(axis.title.y=element_blank()) +} + +## savefig +if ("$uwid" != ''){ + if (!${rotate_plot}){ + Savefig("${file}${mid}.${ext}", p, $uwid, $vhig, "$res", "${ext}") + }else{ + Savefig("${file}${mid}.${ext}", p, $vhig, $uwid, "$res", "${ext}") + } +}else{ + if (!${rotate_plot}){ + Savefig("${file}${mid}.${ext}", p, w_auto, h_auto, "$res", "${ext}") + }else{ + Savefig("${file}${mid}.${ext}", p, h_auto, w_auto, "$res", "${ext}") + } +} +END +} cat <${file}${mid}.r +source('$(cd `dirname $0`; pwd)/rFunction.R') if ($ist){ - install.packages("ggplot2", repo="http://cran.us.r-project.org") - install.packages("reshape2", repo="http://cran.us.r-project.org") - install.packages("scales", repo="http://cran.us.r-project.org") - if(${jitter_bp}){ - install.packages("ggbeeswarm", repo="http://cran.us.r-project.org") - } + installp(c("ggplot2", "reshape2", "scales","ggbeeswarm","dplyr")) } -if(${jitter_bp}){ - library(ggbeeswarm) -}else if(${jitter}){ +if(${boxplot_jitter} || ${violin_jitter} || ${jitter}){ library(ggbeeswarm) } +# else if(${jitter}){ +# library(ggbeeswarm) +# } library(ggplot2) library(reshape2) library(scales) +library(dplyr) + +##### add by lindechun + +s_boxplot_median <- function(dat, more_v=TRUE){ + + ## errorbar(replace median line of boxplot or violin) adapt to sub-xvariable + + errorbarWidth <- function(x){ + y<-mean(unique(x)) + dfd <- function(i,y){ + (i-y)*($sub_box/length(unique(x))) + } + cc<-sapply(x,dfd,y) + return(cc) + } + if (more_v){ + temp1 <- mutate(dat,a1=as.integer(${variable})) + temp1 <- mutate(temp1,a2=as.integer(${xvariable})) + temp1\$a3 <- temp1\$a1+errorbarWidth(temp1\$a2) + temp2 <- temp1 %>% group_by(a3) %>% summarise(median=median(${value})) + + ## force boxplots from geom_boxplot to constant width + ## Ref: https://stackoverflow.com/questions/16705129/force-boxplots-from-geom-boxplot-to-constant-width + + if ("${facet}" != "NoMeAnInGTh_I_n_G_s") { + tab <- xtabs(~${xvariable}+${variable}+${facet},temp1) + tmp <- temp1[c("${variable}","${xvariable}","${value}","${facet}")] + }else{ + tab <- xtabs(~${xvariable}+${variable},temp1) + tmp <- temp1[c("${variable}","${xvariable}","${value}")] + } + + idx <- which(tab==0,arr.ind=TRUE) + + if(dim(idx)[1] != 0){ + fakeLines <- apply(idx, 1, function(x){ + + if (is.integer(dimnames(tab)[[2]])){ + fake_1 <- as.integer(dimnames(tab)[[2]][x[2]]) + }else{ + fake_1 <- dimnames(tab)[[2]][x[2]] + } + + if (is.integer(dimnames(tab)[[1]])){ + fake_2 <- as.integer(dimnames(tab)[[1]][x[1]]) + }else{ + fake_2 <- dimnames(tab)[[1]][x[1]] + } + if ("${facet}" != "NoMeAnInGTh_I_n_G_s") { + if (is.integer(dimnames(tab)[[1]])){ + fake_3 <- as.integer(dimnames(tab)[[3]][x[3]]) + }else{ + fake_3 <- dimnames(tab)[[3]][x[3]] + } + setNames(data.frame(fake_1,fake_2,min(temp1\$${value})-0.06*(max(temp1\$${value})-min(temp1\$${value})),fake_3),names(tmp)) + }else{ + setNames(data.frame(fake_1,fake_2,min(temp1\$${value})-0.06*(max(temp1\$${value})-min(temp1\$${value}))),names(tmp)) + } + } + ) + tmp2 <- rbind(tmp, do.call(rbind, fakeLines)) + }else{ + tmp2 <- tmp + } + + return(list(data_m=tmp2,data_bp_median=temp2,data_m_temp=temp1)) + + }else{ + + temp2 <- dat %>% group_by(${variable}) %>% summarise(median=median(${value})) + return(list(data_m=dat,data_bp_median=temp2)) + } +} + + +###### add by lindechun if(! $melted){ - ID_var <- c("${ID_var}") - ID_var <- ID_var[ID_var!=""] - data <- read.table(file="${file}", sep="\t", header=$header, - row.names=1, quote="", check.names=F) - if ("${gene}" != "FALSE") { - data_m <- as.data.frame(t(data["${gene}", ])) - data_m\$sample = rownames(data_m) - if ("${sampleGroup}" != "FALSE"){ - sampleGroup <- read.table("${sampleGroup}",sep="\t",header=1,check.names=F,row.names=1) - data_m <- merge(data_m, sampleGroup, by="row.names") - } - } else { - if ("$xvariable" != "${variable}"){ - if (length(ID_var) > 0){ - ID_var <- c(ID_var, "${xvariable}") - } else { - ID_var <- c("${xvariable}") - } - data_m <- melt(data, id.vars=ID_var) - } else { - if (length(ID_var) > 0){ - data_m <- melt(data, id.vars=ID_var) - } else { - data_m <- melt(data) - } - } - } + ID_var <- c("${ID_var}") + ID_var <- ID_var[ID_var!=""] + data <- read.table(file="${file}", sep="\t", header=$header, + row.names=1, quote="", check.names=F) + if ("${gene}" != "FALSE") { + data_m <- as.data.frame(t(data["${gene}", ])) + data_m\$Sample = rownames(data_m) + + if ("${sampleGroup}" != "FALSE") { + sampleGroup <- read.table("${sampleGroup}",sep="\t",header=1,check.names=F,row.names=1) + data_m <- merge(data_m, sampleGroup, by="row.names") + }else{ + print("Wainning: Because per x-axis tag contains only one data, so recommend you to use the scatterplot or lines script") + } + }else { + if ("$variable" != "variable") { + if (length(ID_var) > 0){ + ID_var <- c(ID_var, "${variable}") + } else { + ID_var <- c("${variable}") + } + data_m <- melt(data, id.vars=ID_var) + } else { + if (length(ID_var) > 0) { + data_m <- melt(data, id.vars=ID_var) + } else { + data_m <- melt(data) + } + } + } } else { - data_m <- read.table(file="$file", sep="\t", - header=$header, quote="") + data_m <- read.table(file="$file", sep="\t", + header=$header, quote="") } + if (${y_add} != 0){ - data_m\$${value} <- data_m\$${value} + ${y_add} + data_m\$${value} <- data_m\$${value} + ${y_add} } level <- c(${level}) -if ("${legend_cut}" != ""){ - data_m\$${variable} <- cut(data_m\$${variable}, ${legend_cut}) + +if ("${legend_cut}" != "") { + data_m\$${variable} <- cut(data_m\$${xvariable}, ${legend_cut}) } else if (length(level)>1){ - level_i <- level - data_m\$${variable} <- factor(data_m\$${variable}, levels=level_i) + level_i <- level + data_m\$${variable} <- factor(data_m\$${xvariable}, levels=level_i) } x_level <- c(${x_level}) -if ("${x_cut}" != ""){ - data_m\$${xvariable} <- cut(data_m\$${xvariable},${x_cut}) +if ("${x_cut}" != "") { + data_m\$${variable} <- cut(data_m\$${variable},${x_cut}) }else if (length(x_level)){ - data_m\$${xvariable} <- factor(data_m\$${xvariable},levels=x_level) + data_m\$${variable} <- factor(data_m\$${variable},levels=x_level) } + facet_level <- c(${facet_level}) if (length(facet_level)>1) { - data_m\$${facet} <- factor(data_m\$${facet}, + data_m\$${facet} <- factor(data_m\$${facet}, levels=facet_level, ordered=T) } +### add by lindechun +if ("${variable}" == "${xvariable}") { + dat <- s_boxplot_median(data_m, more_v=FALSE) +}else{ + dat <- s_boxplot_median(data_m, more_v=TRUE) +} + +data_m <- dat\$data_m -p <- ggplot(data_m, aes(factor($xvariable), ${value})) + xlab("$xlab") + -ylab("$ylab") + labs(title="$title") - - -if (${violin}){ - p <- p + geom_violin(aes(fill=factor(${variable})), - stat = "ydensity", position = "dodge", trim = TRUE, - scale = "${scale_violin}") + - geom_boxplot(aes(fill=factor(${variable})), alpha=.25, width=0.15, - position = position_dodge(width = .9), outlier.colour='NA') + - stat_summary(aes(group=${variable}), fun.y=mean, - geom="point", fill="black", shape=19, size=1, - position = position_dodge(width = .9)) - - #+ geom_jitter(height = 0) -} else if (${violin_nb}){ - p <- p + geom_violin(aes(fill=factor(${variable})), - stat = "ydensity", position = "dodge", trim = TRUE, - scale = "${scale_violin}") -} else if (${jitter}){ - p <- p + geom_quasirandom(aes(colour=factor(${variable}))) - p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") - #p <- p + geom_jitter(aes(colour=factor(${variable}))) -} else { - if (${notch}){ - if (${outlier}){ - p <- p + geom_boxplot(aes(fill=factor(${variable})), notch=TRUE, - notchwidth=0.3, outlier.colour='NA') - }else{ - p <- p + geom_boxplot(aes(fill=factor(${variable})), notch=TRUE, - notchwidth=0.3) - } - }else { - if (${outlier}){ - p <- p + geom_boxplot(aes(fill=factor(${variable})), - outlier.colour='NA') - }else{ - p <- p + geom_boxplot(aes(fill=factor(${variable}))) - } - } +## calculate point size of jitter +data_nrow=nrow(dat\$data_m) +if (data_nrow < 50) { + jitter_size=1 +}else{ + jitter_size=0.5 } -if (${jitter_bp}){ - #p <- p + geom_jitter(aes(colour=factor(${variable}))) - #p <- p + geom_jitter() - p <- p + geom_quasirandom() +dat\$data_m\$${xvariable} <- factor(data_m\$${xvariable}) +dat\$data_m\$${variable} <- factor(data_m\$${variable}) + +data_m\$${xvariable} <- factor(data_m\$${xvariable}) +data_m\$${variable} <- factor(data_m\$${variable}) + +if ("${facet}" != "NoMeAnInGTh_I_n_G_s") { + dat\$data_m\$${facet} <- factor(data_m\$${facet}) + data_m\$${facet} <- factor(data_m\$${facet}) } -if($scaleY){ - p <- p + $scaleY_x - p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 10, color= "black") + +### add by lindechun + +p <- ggplot(dat\$data_m, aes($variable, ${value})) + xlab("$xlab") + + ylab("$ylab") + labs(title="$title") + +if (${violin}) { + p <- p + geom_violin(aes(color=${xvariable},fill=${xvariable}), + stat = "ydensity", position = "dodge", trim = TRUE, + scale = "${scale_violin}") + + if ("${variable}" != "${xvariable}") { + p <- p + geom_point(data=dat\$data_bp_median,aes(x=a3,y=median), size=1)+ + coord_cartesian(ylim=c(min(dat\$data_m_temp\$${value}),max(dat\$data_m_temp\$${value}))) + }else{ + p <- p+geom_point(data=dat\$data_bp_median,aes(x=${variable}, y=median),size=1) + } + + # stat_summary(aes(group=${variable}), fun.y=mean, + # geom="point", fill="black", shape=19, size=1, + # position = position_dodge(width = .9)) + +} else if (${violin_jitter}) { + p <- p + geom_violin(aes(color=${xvariable}),size=0.5, + stat = "ydensity", position = "dodge", trim = TRUE, + scale = "${scale_violin}")+geom_quasirandom(size=jitter_size) + + if ("${variable}" != "${xvariable}") { + p <- p + geom_point(data=dat\$data_bp_median,aes(x=a3,y=median), size=1.5, shape=17)+ + coord_cartesian(ylim=c(min(dat\$data_m_temp\$${value}),max(dat\$data_m_temp\$${value}))) + }else{ + p <- p+geom_point(data=dat\$data_bp_median,aes(x=${variable},y=median), size=1.5, shape=17) + } + +} else if (${jitter}) { + + p <- p + geom_quasirandom(aes(color=${xvariable}),size=jitter_size) + p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 5, color= "black") +} else { + if (${notch}){ + if (${outlier}){ + p <- p + geom_boxplot(aes(fill=${xvariable},color=${xvariable}), notch=TRUE,width=$sub_box, + notchwidth=0.3, outlier.colour='NA') + }else{ + p <- p + geom_boxplot(aes(fill=${xvariable},color=${xvariable}), notch=TRUE,outlier.size=0.5, width=$sub_box, + notchwidth=0.3) + } + } else { + if (${outlier}){ + p <- p + geom_boxplot(aes(fill=${xvariable},color=${xvariable}), + outlier.colour='NA', width=$sub_box) + }else{ + p <- p + geom_boxplot(aes(fill=${xvariable},color=${xvariable}),outlier.size=0.5, width=$sub_box) + } + } + if ("${variable}" != "${xvariable}") { + p <- p + geom_crossbar(data=dat\$data_bp_median,aes(x=a3,y=median,ymin=median,ymax=median),width=0.8*$sub_box/length(unique(dat\$data_m_temp\$a2)),fatten=0,size=0.7,color="white")+ + coord_cartesian(ylim=c(min(dat\$data_m_temp\$${value}),max(dat\$data_m_temp\$${value}))) + } else { + p <- p + geom_crossbar(data=dat\$data_bp_median,aes(x=${variable},y=median,ymax=median,ymin=median),width=$sub_box,color="white",fatten=0,size=0.7) + } } -if(${outlier}){ - #ylim_zoomin <- boxplot.stats(data_m\$${value})\$stats[c(1,5)] - stats <- boxplot.stats(data_m\$${value})\$stats - ylim_zoomin <- c(stats[1]/${out_scale}, stats[5]*${out_scale}) - p <- p + coord_cartesian(ylim = ylim_zoomin) +if (${boxplot_jitter}) { + p <- p + geom_quasirandom(color="black",size=jitter_size) } -if($color){ - p <- p + scale_fill_manual(values=c(${color_v})) + +if ($scaleY) { + p <- p + $scaleY_x + # p <- p + stat_summary(fun.y = "mean", geom = "text", label="----", size= 5, color= "black") } -if(${rotate_plot}){ - p <- p + coord_flip() +if (${outlier}) { + #ylim_zoomin <- boxplot.stats(dat\$data_m\$${value})\$stats[c(1,5)] + stats <- boxplot.stats(dat\$data_m\$${value})\$stats + ylim_zoomin <- c(stats[1]/${out_scale}, stats[5]*${out_scale}) + p <- p + coord_cartesian(ylim = ylim_zoomin) } -if ("${facet}" != "NoMeAnInGTh_I_n_G_s"){ - p <- p + facet_wrap( ~ ${facet}, nrow=${nrow}, ncol=${ncol}, - scale="${scales}") + +if ($color) { + p <- p + scale_fill_manual(values=c(${color_v}))+scale_colour_manual(values=c(${color_v})) +} + +if (${rotate_plot}) { + p <- p + coord_flip() } +if ("${facet}" != "NoMeAnInGTh_I_n_G_s") { + # p <- p + facet_wrap( ~ ${facet}, nrow=${nrow}, ncol=${ncol},scale="${scales}") + p <- p + facet_wrap( ~ ${facet},scale="${scales}") +} + END `ggplot2_configure` -##cat <>${file}${mid}.r -## -##p <- p + theme_bw() + theme(legend.title=element_blank(), -## panel.grid.major = element_blank(), -## panel.grid.minor = element_blank(), -## legend.key=element_blank(), -## axis.text.x=element_text(angle=${xtics_angle},hjust=1)) -## -##top='top' -##botttom='bottom' -##left='left' -##right='right' -##none='none' -##legend_pos_par <- ${legend_pos} -## -###if ("${legend_pos}" != "right"){ -##p <- p + theme(legend.position=legend_pos_par) -###} -## -## -##p <- p${par} -## -## -##ggsave(p, filename="${file}${mid}.${ext}", dpi=$res, width=$uwid, -##height=$vhig, units=c("cm")) -## -###png(filename="${file}${mid}.png", width=$uwid, height=$vhig, -###res=$res) -###p -###dev.off() -##END if [ "$execute" == "TRUE" ]; then Rscript ${file}${mid}.r -#if [ "$?" == "0" ]; then /bin/rm -f ${file}${mid}.r; fi + if [ "$?" == "0" ]; then + /bin/rm -f ${file}${mid}.r + fi fi - diff --git a/sp_pheatmap.sh b/sp_pheatmap.sh index fc54466..1ab4b24 100755 --- a/sp_pheatmap.sh +++ b/sp_pheatmap.sh @@ -8,48 +8,10 @@ cat < will be transferred @@ -123,24 +85,18 @@ ${txtbld}OPTIONS${txtrst}: [${txtred}Default NA${txtrst}] -Q A file to specify col-annotation with format described above. [${txtred}Default NA${txtrst}] - -Z Annotation color. One can only specify color for each column of row-annotation - or col-annotation. For example, 'class' (two values: C1, C2) and - 'group' (two values:G1, G2) are two row-annotations, - 'type' (three values, T1, T2, T3) and 'size' (four values, 1, 2, 3, 4) - are two col-annoations. - Colors can be specified as <'class=c(C1="blue", C2="yellow"), size=c("white", "green"), type=c(T1="pink", T2="black", T3="cyan")'>. - In R, one can use function to get names of all available colors. - -u The width of output picture.[${txtred}Default 20${txtrst}] - -v The height of output picture.[${txtred}Default 20${txtrst}] + -u The width of output picture.[${txtred}Default auto calculate${txtrst}] + -v The height of output picture.[${txtred}Default auto calculate${txtrst}] -E The type of output figures.[${txtred}Default pdf, accept eps/ps, tex (pictex), png, jpeg, tiff, bmp, svg and wmf)${txtrst}] -r The resolution of output picture.[${txtred}Default 300 ppi${txtrst}] -F Font size [${txtred}Default 14${txtrst}] -p Preprocess data matrix to avoid 'STDERR 0 in cor(t(mat))'. Lowercase

. - [${txtred}Default TRUE${txtrst}] + [${txtred}Default FALSE${txtrst}] -e Execute script (Default) or just output the script. [${bldred}Default TRUE${txtrst}] + -o path of Output.[Default Current path, Optinal] -i Install the required packages. Normmaly should be TRUE if this is your first time run s-plot.[${bldred}Default FALSE${txtrst}] EOF @@ -165,15 +121,14 @@ execute='TRUE' ist='FALSE' legend=' ' na_color='grey' -uwid=20 -vhig=20 +uwid='FALSE' ## modify by lindechun, old: 20 +vhig='FALSE' ## modify by lindechun, old: 20 bias=1 res=300 fontsize=14 ext='pdf' xcol='green' ycol='red' -annotation_colors='NA' mcol='yellow' mid_value_use='FALSE' mid_value='Inf' @@ -188,10 +143,11 @@ generateNA='FALSE' digits='FALSE' annotation_row='NA' annotation_col='NA' -preprocess='TRUE' +preprocess='FALSE' minimum='-Inf' +output=$(pwd) -while getopts "hf:t:a:A:b:B:H:R:c:D:T:p:I:L:d:k:u:v:E:r:F:P:Q:x:y:M:Z:X:s:m:N:Y:Z:G:C:O:e:i:" OPTION +while getopts "hf:t:a:A:b:B:H:R:c:D:T:p:I:L:d:k:u:v:E:r:F:P:Q:x:y:M:Z:X:s:m:N:Y:G:C:O:e:o:i:" OPTION do case $OPTION in h) @@ -232,9 +188,6 @@ do I) clustering_distance_cols=$OPTARG ;; - Z) - annotation_colors=$OPTARG - ;; p) preprocess=$OPTARG ;; @@ -313,6 +266,9 @@ do e) execute=$OPTARG ;; + o) + output=$OPTARG + ;; i) ist=$OPTARG ;; @@ -346,10 +302,12 @@ if test "${preprocess}" == "TRUE"; then dealWithSTD0.py -i ${file}".nostd0" >${file} fi -cat <${file}${mid}.r +cat <$output/$(basename $file)${mid}.r +source('$(cd `dirname $0`; pwd)/rFunction.R') if ($ist){ - install.packages("pheatmap", repo="http://cran.us.r-project.org") + installp("pheatmap",force = F) + # install.packages("pheatmap", repo="http://cran.us.r-project.org") } library(grid) @@ -495,33 +453,60 @@ if ("${color_type}" == "function"){ color_vector <- ${color_vector} } -ann_colors = list(${annotation_colors}) - -if (ann_colors[1][1] == "NA") { - ann_colors = NA -} - -pheatmap(data, kmean_k=$kclu, color=color_vector, -scale="${scale}", border_color=NA, -cluster_rows=${cluster_rows}, cluster_cols=${cluster_cols}, -breaks=legend_breaks, clustering_method="${clustering_method}", -clustering_distance_rows="${clustering_distance_rows}", -clustering_distance_cols="${clustering_distance_cols}", -legend_breaks=legend_breaks, show_rownames=${ytics}, show_colnames=${xtics}, -main="$title", annotation_col=annotation_col, -annotation_row=annotation_row, -annotation_colors = ann_colors, -fontsize=${fontsize}, filename="${file}${mid}.${ext}", width=${uwid}, -height=${vhig}) - +### control width and height add by lin dechun + +if (!is.numeric(${uwid})) { + if ("${annotation_row}" != "NA" || "${annotation_col}" != "NA") { + temp1=ncol(data)+max(sapply(rownames(data),nchar))/10+4 + } else { + temp1=ncol(data)+max(sapply(rownames(data),nchar))/10+2 + } + + temp2=nrow(data)+max(sapply(colnames(data),nchar))/10 + + if (temp1 > temp2){ + temp2=temp2*(8/temp1) + temp1=8 + } else{ + temp1=temp1*(8/temp2) + temp2=8 + } + + pheatmap(data, kmean_k=$kclu, color=color_vector, + scale="${scale}", border_color=NA, + cluster_rows=${cluster_rows}, cluster_cols=${cluster_cols}, + breaks=legend_breaks, clustering_method="${clustering_method}", + clustering_distance_rows="${clustering_distance_rows}", + clustering_distance_cols="${clustering_distance_cols}", + legend_breaks=legend_breaks, show_rownames=${ytics}, show_colnames=${xtics}, + main="$title", annotation_col=annotation_col, + annotation_row=annotation_row, + fontsize=${fontsize}, filename="$output/$(basename $file)${mid}.${ext}", width=temp1, + height=temp2) +}else{ + pheatmap(data, kmean_k=$kclu, color=color_vector, + scale="${scale}", border_color=NA, + cluster_rows=${cluster_rows}, cluster_cols=${cluster_cols}, + breaks=legend_breaks, clustering_method="${clustering_method}", + clustering_distance_rows="${clustering_distance_rows}", + clustering_distance_cols="${clustering_distance_cols}", + legend_breaks=legend_breaks, show_rownames=${ytics}, show_colnames=${xtics}, + main="$title", annotation_col=annotation_col, + annotation_row=annotation_row, + fontsize=${fontsize}, filename="$output/$(basename $file)${mid}.${ext}", width=${uwid}, + height=${vhig}) +} + +cat(system("/bin/rm -f Rplots.pdf",intern=TRUE)) END + if [ "$execute" == "TRUE" ]; then - Rscript ${file}${mid}.r - if [ "$?" == "0" ]; then - #/bin/rm -f ${file}${mid}.r - /bin/rm -f Rplots.pdf + Rscript $output/$(basename $file)${mid}.r + if [ "$?" == "0" ]; then + /bin/rm -f $output/$(basename $file)${mid}.r + /bin/rm -f Rplots.pdf fi fi diff --git a/swap b/swap deleted file mode 100644 index d6e1d30..0000000 --- a/swap +++ /dev/null @@ -1,15 +0,0 @@ - -b The formula for facets.[${bldred}Default no facets, - +facet_grid(level ~ .) means divide by levels of 'level' vertcally. - +facet_grid(. ~ level) means divide by levels of 'level' horizontally. - +facet_grid(lev1 ~ lev2) means divide by lev1 vertically and lev2 - horizontally. - +facet_wrap(~level, ncol=2) means wrap horizontally with 2 - columns. - Example: +facet_wrap(~Size,ncol=6,scale='free') - ${txtrst}] - -d If facet is given, you may want to specifize the order of - variable in your facet, default alphabetically. - [${txtred}Accept sth like - (one level one sentence, separate by';') - data\$size <- factor(data\$size, levels=c("l1", - "l2",...,"l10"), ordered=T) ${txtrst}] diff --git a/swap2 b/swap2 deleted file mode 100644 index 5ad5771..0000000 --- a/swap2 +++ /dev/null @@ -1,11 +0,0 @@ -$facet_o - -p <- ggplot(data, aes(x=${xval},y=${yval})) \ -+ geom_point(aes(color=${color})) \ -+ scale_colour_gradient(low="green", high="red", -name="$col_legend" ${log}) \ -+ labs(x="$xlab", y="$ylab") + labs(title="$title") - -#if ("$facet" != ""){ -# facet=$facet -p <- p ${facet} diff --git a/tips b/tips deleted file mode 100644 index e69de29..0000000 diff --git a/tutorial_markdown/2017-07-09-R-boxplot.md b/tutorial_markdown/2017-07-09-R-boxplot.md new file mode 100644 index 0000000..02593f3 --- /dev/null +++ b/tutorial_markdown/2017-07-09-R-boxplot.md @@ -0,0 +1,420 @@ +--- +title: R 学习 - 箱线图 +author: ct +layout: post +categories: + - R +tags: + - R + - Bioinfo +--- + + +## 箱线图 + +箱线图是能同时反映数据统计量和整体分布,又很漂亮的展示图。在2014年的Nature Method上有2篇Correspondence论述了使用箱线图的好处和一个在线绘制箱线图的工具。就这样都可以发两篇Nature method,没天理,但也说明了箱线图的重要意义。 + +下面这张图展示了Bar plot、Box plot、Volin plot和Bean plot对数据分布的反应。从Bar plot上只能看到数据标准差或标准误不同;Box plot可以看到数据分布的集中性不同;Violin plot和Bean plot展示的是数据真正的分布,尤其是对Biomodal数据的展示。 + +Boxplot从下到上展示的是最小值,第一四分位数 (箱子的下边线)、中位数 (箱子中间的线)、第三四分位数 (箱子上边线)、最大值,具体解读参见 http://mp.weixin.qq.com/s/t3UTI_qAIi0cy1g6ZmHtwg。 + +![]({{ site.img_url}}/splot/boxplot_nm.png) + +* Nature Method文章 + +### 一步步解析箱线图绘制 + +假设有这么一个基因表达矩阵,第一列为基因名字,后面几列为样品名字,想绘制下样品中基因表达的整体分布。 + +```r +profile="Name;2cell_1;2cell_2;2cell_3;4cell_1;4cell_2;4cell_3;zygote_1;zygote_2;zygote_3 +A;4;6;7;3.2;5.2;5.6;2;4;3 +B;6;8;9;5.2;7.2;7.6;4;6;5 +C;8;10;11;7.2;9.2;9.6;6;8;7 +D;10;12;13;9.2;11.2;11.6;8;10;9 +E;12;14;15;11.2;13.2;13.6;10;12;11 +F;14;16;17;13.2;15.2;15.6;12;14;13 +G;15;17;18;14.2;16.2;16.6;13;15;14 +H;16;18;19;15.2;17.2;17.6;14;16;15 +I;17;19;20;16.2;18.2;18.6;15;17;16 +J;18;20;21;17.2;19.2;19.6;16;18;17 +L;19;21;22;18.2;20.2;20.6;17;19;18 +M;20;22;23;19.2;21.2;21.6;18;20;19 +N;21;23;24;20.2;22.2;22.6;19;21;20 +O;22;24;25;21.2;23.2;23.6;20;22;21" +``` + +读入数据并转换为ggplot2需要的长数据表格式 (经过前面几篇的练习,这应该都很熟了) + +```r +profile_text <- read.table(text=profile, header=T, row.names=1, quote="",sep=";", check.names=F) +# 在melt时保留位置信息 +# melt格式是ggplot2画图最喜欢的格式 +# 好好体会下这个格式,虽然多占用了不少空间,但是确实很方便 + +library(ggplot2) +library(reshape2) +data_m <- melt(profile_text) +head(data_m) +``` + + variable value + 1 2cell_1 4 + 2 2cell_1 6 + 3 2cell_1 8 + 4 2cell_1 10 + 5 2cell_1 12 + 6 2cell_1 14 + + +像往常一样,就可以直接画图了。 + +```r +# variable和value为矩阵melt后的两列的名字,内部变量, variable代表了点线的属性,value代表对应的值。 +p <- ggplot(data_m, aes(x=variable, y=value),color=variable) + +geom_boxplot() + +theme(axis.text.x=element_text(angle=50,hjust=0.5, vjust=0.5)) + +theme(legend.position="none") +p +# 图会存储在当前目录的Rplots.pdf文件中,如果用Rstudio,可以不运行dev.off() +dev.off() +``` + +箱线图出来了,看上去还可以,再加点色彩。 + +![]({{ site.img_url }}/splot/boxplot_1.png) + +```r +# variable和value为矩阵melt后的两列的名字,内部变量, variable代表了点线的属性,value代表对应的值。 +p <- ggplot(data_m, aes(x=variable, y=value),color=variable) + +geom_boxplot(aes(fill=factor(variable))) + +theme(axis.text.x=element_text(angle=50,hjust=0.5, vjust=0.5)) + +theme(legend.position="none") +p +# 图会存储在当前目录的Rplots.pdf文件中,如果用Rstudio,可以不运行dev.off() +dev.off() +``` + +![]({{ site.img_url }}/splot/boxplot_2.png) + +再看看Violin plot + +```r +# variable和value为矩阵melt后的两列的名字,内部变量, variable代表了点线的属性,value代表对应的值。 +p <- ggplot(data_m, aes(x=variable, y=value),color=variable) + +geom_violin(aes(fill=factor(variable))) + +theme(axis.text.x=element_text(angle=50,hjust=0.5, vjust=0.5)) + +theme(legend.position="none") +p +# 图会存储在当前目录的Rplots.pdf文件中,如果用Rstudio,可以不运行dev.off() +dev.off() +``` + +![]({{ site.img_url }}/splot/boxplot_3.png) + +还有Jitter plot (这里使用的是ggbeeswarm包) + +```r +library(ggbeeswarm) +# 为了更好的效果,只保留其中一个样品的数据 +# grepl类似于Linux的grep命令,获取特定模式的字符串 + +data_m2 <- data_m[grepl("_3", data_m$variable),] + +# variable和value为矩阵melt后的两列的名字,内部变量, variable代表了点线的属性,value代表对应的值。 +p <- ggplot(data_m2, aes(x=variable, y=value),color=variable) + +geom_quasirandom(aes(colour=factor(variable))) + +theme_bw() + theme(panel.grid.major = element_blank(), +panel.grid.minor = element_blank(), legend.key=element_blank()) + +theme(legend.position="none") +# 也可以用geom_jitter(aes(colour=factor(variable)))代替geom_quasirandom(aes(colour=factor(variable))) +# 但个人认为geom_quasirandom给出的结果更有特色 + +ggsave(p, filename="jitterplot.pdf", width=14, height=8, units=c("cm")) +``` + +![]({{ site.img_url }}/splot/boxplot_4.png) + +### 绘制单个基因 (A)的箱线图 + +为了更好的展示效果,下面的矩阵增加了样品数量和样品的分组信息。 + +```r +profile="Name;2cell_1;2cell_2;2cell_3;2cell_4;2cell_5;2cell_6;4cell_1;4cell_2;4cell_3;4cell_4;4cell_5;4cell_6;zygote_1;zygote_2;zygote_3;zygote_4;zygote_5;zygote_6 +A;4;6;7;5;8;6;3.2;5.2;5.6;3.6;7.6;4.8;2;4;3;2;4;2.5 +B;6;8;9;7;10;8;5.2;7.2;7.6;5.6;9.6;6.8;4;6;5;4;6;4.5" + +profile_text <- read.table(text=profile, header=T, row.names=1, quote="",sep=";", check.names=F) + +data_m = data.frame(t(profile_text['A',])) +data_m$sample = rownames(data_m) +# 只挑选显示部分 +# grepl前面已经讲过用于匹配 +data_m[grepl('_[123]', data_m$sample),] +``` + + A sample + 2cell_1 4.0 2cell_1 + 2cell_2 6.0 2cell_2 + 2cell_3 7.0 2cell_3 + 4cell_1 3.2 4cell_1 + 4cell_2 5.2 4cell_2 + 4cell_3 5.6 4cell_3 + zygote_1 2.0 zygote_1 + zygote_2 4.0 zygote_2 + zygote_3 3.0 zygote_3 + +获得样品分组信息 (这个例子比较特殊,样品的分组信息就是样品名字下划线前面的部分) + +```r +# 可以利用strsplit分割,取出其前面的字符串 +# R中复杂的输出结果多数以列表的形式体现,在之前的矩阵操作教程中 +# 提到过用str函数来查看复杂结果的结构,并从中获取信息 +group = unlist(lapply(strsplit(data_m$sample,"_"), function(x) x[1])) +data_m$group = group +data_m[grepl('_[123]', data_m$sample),] +``` + + A sample group + 2cell_1 4.0 2cell_1 2cell + 2cell_2 6.0 2cell_2 2cell + 2cell_3 7.0 2cell_3 2cell + 4cell_1 3.2 4cell_1 4cell + 4cell_2 5.2 4cell_2 4cell + 4cell_3 5.6 4cell_3 4cell + zygote_1 2.0 zygote_1 zygote + zygote_2 4.0 zygote_2 zygote + zygote_3 3.0 zygote_3 zygote + +如果没有这个规律,也可以提到类似于下面的文件,指定样品所属的组的信息。 + +```r +sampleGroup_text="Sample;Group +zygote_1;zygote +zygote_2;zygote +zygote_3;zygote +zygote_4;zygote +zygote_5;zygote +zygote_6;zygote +2cell_1;2cell +2cell_2;2cell +2cell_3;2cell +2cell_4;2cell +2cell_5;2cell +2cell_6;2cell +4cell_1;4cell +4cell_2;4cell +4cell_3;4cell +4cell_4;4cell +4cell_5;4cell +4cell_6;4cell" + +#sampleGroup = read.table(text=sampleGroup_text,sep="\t",header=1,check.names=F,row.names=1) + +#data_m <- merge(data_m, sampleGroup, by="row.names") + +# 会获得相同的结果,脚本注释掉了以免重复执行引起问题。 +``` + +矩阵准备好了,开始画图了 (小提琴图做例子,其它类似) + +```r +# 调整下样品出现的顺序 +data_m$group <- factor(data_m$group, levels=c("zygote","2cell","4cell")) +# group和A为矩阵中两列的名字,group代表了值的属性,A代表基因A对应的表达值。 +# 注意看修改了的地方 +p <- ggplot(data_m, aes(x=group, y=A),color=group) + +geom_violin(aes(fill=factor(group))) + +theme(axis.text.x=element_text(angle=50,hjust=0.5, vjust=0.5)) + +theme(legend.position="none") +p +# 图会存储在当前目录的Rplots.pdf文件中,如果用Rstudio,可以不运行dev.off() +dev.off() +``` + +![]({{ site.img_url }}/splot/boxplot_5.png) + +### 长矩阵绘制箱线图 + +常规矩阵绘制箱线图要求必须是个方正的矩阵输入,而有时想比较的几个组里面检测的值数目不同。比如有三个组,GrpA组检测了6个病人,GrpB组检测了10个病人,GrpC组是12个正常人的检测数据。这时就很难形成一个行位检测值,列为样品的矩阵,长表格模式就适合与这种情况。 + +```r +long_table <- "Grp;Value +GrpA;10 +GrpA;11 +GrpA;12 +GrpB;5 +GrpB;4 +GrpB;3 +GrpB;2 +GrpC;2 +GrpC;3" + +long_table <- read.table(text=long_table,sep="\t",header=1,check.names=F) + +p <- ggplot(data_m, aes(x=Grp, y=Value),color=Grp) + +geom_violin(aes(fill=factor(Grp))) + +theme(axis.text.x=element_text(angle=50,hjust=0.5, vjust=0.5)) + +theme(legend.position="none") +p + +``` + +长表格形式自身就是常规矩阵melt后的格式,这种用来绘制箱线图就很简单了,就不举例子了。 + + +## 箱线图 - 一步绘制 + +绘图时通常会碰到两个头疼的问题: + +1. 有时需要绘制很多的图,唯一的不同就是输入文件,其它都不需要修改。如果用R脚本,需要反复替换文件名,繁琐又容易出错。 (R也有命令行参数,不熟,有经验的可以尝试下) + +2. 每次绘图都需要不断的调整参数,时间久了不用,就忘记参数怎么设置了;或者调整次数过多,有了很多版本,最后不知道用哪个了。 + +为了简化绘图、维持脚本的一致,我用`bash`对绘图命令做了一个封装,通过配置修改命令行参数,生成相应的绘图脚本,然后再绘制。 + +首先把测试数据存储到文件中方便调用。数据矩阵存储在`boxplot.normal.data`、`sampleGroup`和`boxplot.melt.data`文件中 (TAB键分割,内容在文档最后。如果你手上有自己的数据,也可以拿来用)。 + + +使用正常矩阵默认参数绘制箱线图 + +``` +# -f: 指定输入的矩阵文件,第一列为行名字,第一行为header + 列数不限,列名字不限;行数不限,行名字默认为文本 +sp_boxplot.sh -f boxplot.normal.data +``` + +箱线图出来了,但有点小乱。 + +![stat_smooth]({{ site.img_url }}/splot/boxplot_6.png) + +``` +# -f: 指定输入的矩阵文件,第一列为行名字,第一行为header + 列数不限,列名字不限;行数不限,行名字默认为文本 +# -P: none, 去掉legend (uppercase P) +# -b: X-axis旋转45度 +# -V: TRUE 绘制小提琴图 +sp_boxplot.sh -f boxplot.normal.data -P none -b 45 -V TRUE +``` + +![stat_smooth]({{ site.img_url }}/splot/boxplot_7.png) + +绘制单个基因的小提琴图加抖动图 + +``` +# -q: 指定某一行的名字,此处为基因名,绘制基因A的表达图谱 +# -Q: 指定样本分组,绘制基因A在不同样品组的表达趋势 +# -F Group: sampleGroup中第二列的名字,指代分组信息,根据需要修改 +# -J TRUE: 绘制抖动图 jitter plot +# -L: 设置X轴样品组顺序 +# -c TRUE -C "'red', 'pink', 'blue'": 指定每个箱线图的颜色 +sp_boxplot.sh -f boxplot.normal.data -q A -Q sampleGroup -F Group -V TRUE -J TRUE -L "'zygote','2cell','4cell'" -c TRUE -C "'red', 'pink', 'blue'" -P none +``` + +![stat_smooth]({{ site.img_url }}/splot/boxplot_8.png) + +使用melted矩阵默认参数绘箱线图 + +``` +# -f: 指定输入文件 +# -m TRUE: 指定输入的矩阵为melted format +# -d Expr:指定表达值所在的列 +# -F Rep: 指定子类所在列,也就是legend +# -a Group:指定X轴分组信息 +# -j TRUE: jitter plot +sp_boxplot.sh -f boxplot.melt.data -m TRUE -d Expr -F Rep -a Group -j TRUE +``` + +![stat_smooth]({{ site.img_url }}/splot/boxplot_9.png) + +``` +# 如果没有子类,则-a和-F指定为同一值 +# -R TRUE: 旋转boxplot +sp_boxplot.sh -f boxplot.melt.data -m TRUE -d Expr -a Group -F Group -J TRUE -R TRUE +``` + +![stat_smooth]({{ site.img_url }}/splot/boxplot_10.png) + +参数中最需要注意的是**引号**的使用: + +* 外层引号与内层引号不能相同 +* 凡参数值中包括了`空格`,`括号`,`逗号`等都用引号括起来作为一个整体。 + + +为了推广,也为了激起大家的热情,如果想要`sp_boxplot.sh`脚本的,还需要劳烦大家动动手,转发此文章到朋友圈,并留言索取。 + +也希望大家能一起开发,完善功能。 + + +```r +#boxplot.normal.data +Name 2cell_1 2cell_2 2cell_3 2cell_4 2cell_5 2cell_6 4cell_1 4cell_2 4cell_3 4cell_4 4cell_5 4cell_6 zygote_1 zygote_2 zygote_3 zygote_4 zygote_5 zygote_6 +A 4 6 7 5 8 6 3.2 5.2 5.6 3.6 7.6 4.8 2 4 3 2 4 2.5 +B 6 8 9 7 10 8 5.2 7.2 7.6 5.6 9.6 6.8 4 6 5 4 6 4.5 +C 8 10 11 9 12 10 7.2 9.2 9.6 7.6 11.6 8.8 6 8 7 6 8 6.5 +D 10 12 13 11 14 12 9.2 11.2 11.6 9.6 13.6 10.8 8 10 9 8 10 8.5 +E 12 14 15 13 16 14 11.2 13.2 13.6 11.6 15.6 12.8 10 12 11 10 12 10.5 +F 14 16 17 15 18 16 13.2 15.2 15.6 13.6 17.6 14.8 12 14 13 12 14 12.5 +G 15 17 18 16 19 17 14.2 16.2 16.6 14.6 18.6 15.8 13 15 14 13 15 13.5 +H 16 18 19 17 20 18 15.2 17.2 17.6 15.6 19.6 16.8 14 16 15 14 16 14.5 +I 17 19 20 18 21 19 16.2 18.2 18.6 16.6 20.6 17.8 15 17 16 15 17 15.5 +J 18 20 21 19 22 20 17.2 19.2 19.6 17.6 21.6 18.8 16 18 17 16 18 16.5 +L 19 21 22 20 23 21 18.2 20.2 20.6 18.6 22.6 19.8 17 19 18 17 19 17.5 +M 20 22 23 21 24 22 19.2 21.2 21.6 19.6 23.6 20.8 18 20 19 18 20 18.5 +N 21 23 24 22 25 23 20.2 22.2 22.6 20.6 24.6 21.8 19 21 20 19 21 19.5 +O 22 24 25 23 26 24 21.2 23.2 23.6 21.6 25.6 22.8 20 22 21 20 22 20.5 +``` + + + +```r +#boxplot.melt.data + +Gene Sample Group Expr Rep +A zygote_1 zygote 2 1 +A zygote_2 zygote 4 2 +A zygote_3 zygote 3 3 +A zygote_4 zygote 2 4 +A zygote_5 zygote 4 5 +A zygote_6 zygote 2.5 6 +A 2cell_1 2cell 4 1 +A 2cell_2 2cell 6 2 +A 2cell_3 2cell 7 3 +A 2cell_4 2cell 5 4 +A 2cell_5 2cell 8 5 +A 2cell_6 2cell 6 6 +A 4cell_1 4cell 3.2 1 +A 4cell_2 4cell 5.2 2 +A 4cell_3 4cell 5.6 3 +A 4cell_4 4cell 3.6 4 +A 4cell_5 4cell 7.6 5 +A 4cell_6 4cell 4.8 6 +``` + +```r +#sampleGroup +Sample Group +zygote_1 zygote +zygote_2 zygote +zygote_3 zygote +zygote_4 zygote +zygote_5 zygote +zygote_6 zygote +2cell_1 2cell +2cell_2 2cell +2cell_3 2cell +2cell_4 2cell +2cell_5 2cell +2cell_6 2cell +4cell_1 4cell +4cell_2 4cell +4cell_3 4cell +4cell_4 4cell +4cell_5 4cell +4cell_6 4cell +``` + +## Reference + +* {{ site.url }}/2017/06/R-Rstudio +