Created
December 10, 2017 14:55
-
-
Save ShixiangWang/54b09bf423a518de1baa23c6a2f5f7d3 to your computer and use it in GitHub Desktop.
绘制组间差异箱线图
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pltDiff = function(data=NULL, sample=NULL, target=NULL, | |
group1, group2, group1.name="group1", | |
group2.name="group2", title="data", x_lab="", y_lab="", | |
notch=TRUE){ | |
require(ggpubr, quietly = TRUE) | |
if(!is.data.frame(data)) stop("Wrong input! Please check your dataset. The input data type must be data.frame.") | |
a = data.frame(value=data[, target], group=ifelse(!(data[,sample]%in%c(group1,group2)), | |
NA, ifelse(data[,sample]%in%group1, group1.name, group2.name))) | |
a = a[a$group%in%c(group1.name, group2.name), ] | |
## plot | |
theme_wsx <- function(..., bg="white", dist=0.5){ | |
require(grid) | |
theme_bw(...) + theme(axis.line = element_line(size=0.7, color = "black"), | |
plot.margin = unit(rep(dist,4), "lines"), | |
legend.position = c(0.85, 0.7), | |
panel.grid.major = element_blank(), | |
panel.grid.minor = element_blank(), | |
panel.border = element_blank(), panel.background = element_blank(), | |
plot.title = element_text(hjust = 0.5), | |
plot.subtitle = element_text(hjust = 0.5)) | |
} | |
if(group1.name=="UP" | group1.name=="DOWN"){ | |
a$group <- factor(a$group, levels=c("DOWN", "UP")) | |
} | |
p <- ggboxplot(a, x="group", y="value", notch = notch, outlier.shape=NA) + | |
stat_boxplot(geom="errorbar", width=.3) + geom_point(position = "jitter", size=.1, alpha=.5) | |
p1 <- p + labs(x=x_lab, y=y_lab) | |
p1 <- ggpar(p1, legend = "none", title = title) + theme_wsx(base_size=8) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment