R語言——小提琴圖 - - 科研貓

先貼代碼

# Violin #

# define the data file folder here

data.file = "demo.txt" #<-- define your data file here

violin.color = "random" #<-- define the color of box

? ? ? ? ? ? ? ? ? ? ? ? # use "random" to draw multiple colors

x.axis.label = "Cancer type" #<-- define the label of x axis

y.axis.label = "Expression value" #<-- define the label of x axis

options(stringsAsFactors = F)

options(warn = -1)

# Check R packages required here

if(!requireNamespace("RColorBrewer")){

? install.packages("RColorBrewer")

}

library(RColorBrewer)

if(!requireNamespace("ggplot2")){

? install.packages("ggplot2")

}

library(ggplot2)

#read in the data file

data = read.table(data.file, sep="\t", header=T)

colnames(data) = c("Value","Group")

#draw violin plots

if(toupper(violin.color) == "RANDOM"){

? ggplot(data,aes(Group,Value,fill=Group))+

? ? geom_violin(adjust=1,trim=T)+

? ? geom_boxplot(width=0.3,fill="white",alpha=0.8,outlier.colour=NA)+

? ? stat_summary(fun.y=mean,geom="point",fill='white',shape=21,size=2)+

? ? theme_bw()+

? ? theme(axis.text.x=element_text(angle=60,hjust=1,size=10))+

? ? xlab(x.axis.label)+

? ? ylab(y.axis.label)+

? ? guides(fill=F)

}else{

? ggplot(data,aes(Group,Value))+

? ? geom_violin(adjust=1,trim=T,fill=violin.color)+

? ? geom_boxplot(width=0.3,fill="white",alpha=0.8,outlier.colour=NA)+

? ? stat_summary(fun.y=mean,geom="point",fill='white',shape=21,size=2)+

? ? theme_bw()+

? ? theme(axis.text.x=element_text(angle=60,hjust=1,size=10))+

? ? xlab(x.axis.label)+

? ? ylab(y.axis.label)+

? ? guides(fill=F)

}



# 數(shù)據(jù)示例 #

12.53248119 AML

13.03209628 AML

12.46783029 AML

12.82908844 AML

11.39974676 AC

11.09084847 AC

11.51240794 AC

11.55964911 AC

11.77063751 AC

10.78955345 AC

11.68130246 AC

11.80625844 AC

11.31851773 AC

11.73438553 BUC

11.8051308 BUC

12.16311259 BUC

11.67048307 BUC

12.0448187 BUC

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容