加载相应的R包与数据设置
library('ggplot2')########################画图
library('reshape2')########################melt
library('grid') ########################分面
A =rep( c("A","B","C","D"),each=2)
B = c(6.332968,9.368328,6.674348,4.127901,5.192845,6.652865,7.829350,6.995062)
C = c(5.367671,7.286253,5.217053,3.875520,6.679444,6.127819,5.091166,7.942029)
D = c(5.171107,6.232718,5.320568,4.924498,7.140883,4.228142,5.793514,6.347785)
E = c(5.533754,6.152393,6.113618,4.960935,5.959568,5.078903,4.871103,5.223206)
F = rep(c("sample1","sample2"),len=4)
dat = data.frame(A,B,C,D,E)
names(dat)[1] = c("type")
names(dat)[2:5]=F
dat = melt(dat,variable.name="Sample",value.name = "Num")
head(dat)
绘制基本的箱线图
##################按照类型进行统计
P_box=ggplot(data=dat,aes(x=type,y=Num)) +
geom_boxplot(fill="grey",width=0.4,notch=F)+ ##########填充颜色fill, 宽,中位线缺刻notch=T
labs(x="type",y="Num")+
theme(plot.title = element_text(size = 25,face = "bold", vjust = 0.5, hjust = 0.5),
legend.title = element_blank(),
legend.text = element_text(size = 18, face = "bold"),
legend.position = 'right',
legend.key.size=unit(0.8,'cm'),
axis.ticks.x=element_blank(),###########取消x轴刻度线
axis.text.x=element_text(size = 10,face = "bold", vjust = 0.5, hjust = 0.5),############刻度标签文字大小等设置
axis.text.y=element_text(size = 10,face = "bold", vjust = 0.5, hjust = 0.5),
axis.title.x = element_text(size = 20,face = "bold", vjust = 0.5, hjust = 0.5),
axis.title.y = element_text(size = 20,face = "bold", vjust = 0.5, hjust = 0.5),
######取消默认的背景颜色方框等
panel.background = element_rect(fill = "transparent",colour = "black"),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
plot.background = element_rect(fill = "transparent",colour = "black"))
print(P_box)
利用样品进行分面
# 基于样品进行分面
P_box=ggplot(data=dat,aes(x=type,y=Num)) +
geom_boxplot(fill="grey",width=0.4,notch=F)+
labs(x="type",y="Num")+
theme(plot.title = element_text(size = 25,face = "bold", vjust = 0.5, hjust = 0.5),
legend.title = element_blank(),
legend.text = element_text(size = 18, face = "bold"),
legend.position = 'right',
legend.key.size=unit(0.8,'cm'),
axis.ticks.x=element_blank(),
axis.text.x=element_text(size = 10,face = "bold", vjust = 0.5, hjust = 0.5),
axis.text.y=element_text(size = 10,face = "bold", vjust = 0.5, hjust = 0.5),
axis.title.x = element_text(size = 20,face = "bold", vjust = 0.5, hjust = 0.5),
axis.title.y = element_text(size = 20,face = "bold", vjust = 0.5, hjust = 0.5),
panel.background = element_rect(fill = "transparent",colour = "black"),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank(),
plot.background = element_rect(fill = "transparent",colour = "black"))+
facet_grid(.~Sample) #########分面
print(P_box)
如果想提升自己的绘图技能,我们推荐:R语言绘图基础(ggplot2)
1. 文章越来越难发?是你没发现新思路,基因家族分析发2-4分文章简单快速,学习链接:基因家族分析实操课程、基因家族文献思路解读
2. 转录组数据理解不深入?图表看不懂?点击链接学习深入解读数据结果文件,学习链接:转录组(有参)结果解读;转录组(无参)结果解读
3. 转录组数据深入挖掘技能-WGCNA,提升你的文章档次,学习链接:WGCNA-加权基因共表达网络分析
4. 转录组数据怎么挖掘?学习链接:转录组标准分析后的数据挖掘、转录组文献解读
5. 微生物16S/ITS/18S分析原理及结果解读、OTU网络图绘制、cytoscape与网络图绘制课程
6. 生物信息入门到精通必修基础课:linux系统使用、perl入门到精通、perl语言高级、R语言入门、R语言画图
7. 医学相关数据挖掘课程,不用做实验也能发文章:TCGA-差异基因分析、GEO芯片数据挖掘、GEO芯片数据标准化、GSEA富集分析课程、TCGA临床数据生存分析、TCGA-转录因子分析、TCGA-ceRNA调控网络分析
8.其他,二代测序转录组数据自主分析、NCBI数据上传、二代测序数据解读
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!