火山图是散点图的一种,它将统计测试中的统计显著性量度和变化幅度相结合,从而能够帮助快速直观地识别那些变化幅度较大且具有统计学意义的数据点。本文将通过Matlab绘制好看的火山图,需要的可以参考一下
这里画了一个示例:
数据来源
绘制效果:
代码及说明:
使用代码时只需要改一开始导入的数据,和代码提示中X坐标区域范围和Y坐标区域范围,完整代码如下所示:
% 读取数据
data=readmatrix('volcano.txt');
logFC=data(:,2);
padj=data(:,3);
DB_not=(padj>0.5)|(logFC<0.5&logFC>-0.5);
DB_up=padj<=0.05&logFC>=0.5;
DB_down=padj<=0.05&logFC<=-0.5;
ax=gca;
hold(ax,'on');
grid(ax,'on');
% 需要适度调整的属性:坐标区域范围及刻度===================================
ax.XLim=[-5,5];
ax.YLim=[-10,300];
ax.XTick=-5:2.5:5;
ax.YTick=0:50:300;
% =========================================================================
ax.XLabel.String='log_2(FoldChange)';
ax.XLabel.FontSize=14;
ax.XLabel.FontName='Cambria';
ax.XLabel.FontWeight='bold';
ax.YLabel.String='-log_{10}(padj)';
ax.YLabel.FontSize=14;
ax.YLabel.FontName='Cambria';
ax.YLabel.FontWeight='bold';
ax.Color=[235,235,235]./255;
ax.GridColor=[1 1 1];
ax.LineWidth=1.4;
ax.GridAlpha=0.5;
ax.XColor=[44,62,80]./255;
ax.YColor=[44,62,80]./255;
Hdl_not=scatter(logFC(DB_not),-log(padj(DB_not))./log(10),30,'filled',...
'MarkerFaceColor',[190,190,190]./255,'MarkerEdgeColor',[190,190,190]./255,...
'MarkerFaceAlpha',0.6);
Hdl_up=scatter(logFC(DB_up),-log(padj(DB_up))./log(10),30,'filled',...
'MarkerFaceColor',[196,88,62]./255,'MarkerEdgeColor',[196,88,62]./255,...
'MarkerFaceAlpha',0.6);
Hdl_down=scatter(logFC(DB_down),-log(padj(DB_down))./log(10),30,'filled',...
'MarkerFaceColor',[1,114,182]./255,'MarkerEdgeColor',[1,114,182]./255,...
'MarkerFaceAlpha',0.6);
plot([ax.XLim(1),ax.XLim(2)],[-log(0.05)/log(10),-log(0.05)/log(10)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
plot([-0.5,-0.5],[ax.YLim(1),ax.YLim(2)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
plot([0.5,0.5],[ax.YLim(1),ax.YLim(2)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
lgd=legend(ax,[Hdl_up,Hdl_not,Hdl_down],{'up','not','down'});
lgd.Title.String='threshold';
lgd.FontSize=12;
lgd.Title.FontSize=13;
lgd.EdgeColor=[44,62,80]./255;
lgd.TextColor=[44,62,80]./230;
lgd.FontName='Cambria';
lgd.Location='best';
可以看到各种参数设置颇多,一切为了画图质量hiahiahia,要是懒得设置建议直接发复制粘贴,有更强的审美的可以自行改写嗷。
如果希望显示显示坐标区域外的点,请使用如下代码:
% 读取数据
data=readmatrix('volcano.txt');
logFC=data(:,2);
padj=data(:,3);
DB_not=(padj>0.5)|(logFC<0.5&logFC>-0.5);
DB_up=padj<=0.05&logFC>=0.5;
DB_down=padj<=0.05&logFC<=-0.5;
ax=gca;
hold(ax,'on');
grid(ax,'on');
% 需要适度调整的属性:坐标区域范围及刻度===================================
ax.XLim=[-8,8];
ax.YLim=[-10,200];
ax.XTick=-5:2.5:5;
ax.YTick=0:50:300;
% ==========================================================================
DB_down_out=(-log(padj)./log(10)>ax.YLim(2)&logFC<=-0.5)|logFC<ax.XLim(1);
DB_down_out_Set=[logFC(DB_down_out),-log(padj(DB_down_out))./log(10)];
DB_down_out_Set(DB_down_out_Set(:,1)<ax.XLim(1),1)=ax.XLim(1);
DB_down_out_Set(DB_down_out_Set(:,2)>ax.YLim(2),2)=ax.YLim(2);
DB_up_out=(-log(padj)./log(10)>ax.YLim(2)&logFC>=0.5)|logFC>ax.XLim(2);
DB_up_out_Set=[logFC(DB_up_out),-log(padj(DB_up_out))./log(10)];
DB_up_out_Set(DB_up_out_Set(:,1)>ax.XLim(2),1)=ax.XLim(2);
DB_up_out_Set(DB_up_out_Set(:,2)>ax.YLim(2),2)=ax.YLim(2);
% =========================================================================
ax.XLabel.String='log_2(FoldChange)';
ax.XLabel.FontSize=14;
ax.XLabel.FontName='Cambria';
ax.XLabel.FontWeight='bold';
ax.YLabel.String='-log_{10}(padj)';
ax.YLabel.FontSize=14;
ax.YLabel.FontName='Cambria';
ax.YLabel.FontWeight='bold';
ax.Color=[235,235,235]./255;
ax.GridColor=[1 1 1];
ax.LineWidth=1.4;
ax.GridAlpha=0.5;
ax.XColor=[44,62,80]./255;
ax.YColor=[44,62,80]./255;
Hdl_not=scatter(logFC(DB_not),-log(padj(DB_not))./log(10),30,'filled',...
'MarkerFaceColor',[190,190,190]./255,'MarkerEdgeColor',[190,190,190]./255,...
'MarkerFaceAlpha',0.6);
Hdl_up=scatter(logFC(DB_up),-log(padj(DB_up))./log(10),30,'filled',...
'MarkerFaceColor',[196,88,62]./255,'MarkerEdgeColor',[196,88,62]./255,...
'MarkerFaceAlpha',0.6);
Hdl_down=scatter(logFC(DB_down),-log(padj(DB_down))./log(10),30,'filled',...
'MarkerFaceColor',[1,114,182]./255,'MarkerEdgeColor',[1,114,182]./255,...
'MarkerFaceAlpha',0.6);
% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
scatter(DB_up_out_Set(:,1),DB_up_out_Set(:,2),30,'filled','Marker','+',...
'MarkerFaceColor',[196,88,62]./255,'MarkerEdgeColor',[196,88,62]./255,...
'MarkerFaceAlpha',0.6,'LineWidth',1);
scatter(DB_down_out_Set(:,1),DB_down_out_Set(:,2),30,'filled','Marker','+',...
'MarkerFaceColor',[1,114,182]./255,'MarkerEdgeColor',[1,114,182]./255,...
'MarkerFaceAlpha',0.6,'LineWidth',1);
% -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
plot([ax.XLim(1),ax.XLim(2)],[-log(0.05)/log(10),-log(0.05)/log(10)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
plot([-0.5,-0.5],[ax.YLim(1),ax.YLim(2)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
plot([0.5,0.5],[ax.YLim(1),ax.YLim(2)],...
'LineWidth',1.2,'Color',[.2,.2,.2],'LineStyle','-.')
lgd=legend(ax,[Hdl_up,Hdl_not,Hdl_down],{'up','not','down'});
lgd.Title.String='threshold';
lgd.FontSize=12;
lgd.Title.FontSize=13;
lgd.EdgeColor=[44,62,80]./255;
lgd.TextColor=[44,62,80]./230;
lgd.FontName='Cambria';
lgd.Location='best';
到此这篇关于如何利用Matlab绘制出好看的火山图的文章就介绍到这了,更多相关Matlab绘制火山图内容请搜索编程学习网以前的文章希望大家以后多多支持编程学习网!
沃梦达教程
本文标题为:如何利用Matlab绘制出好看的火山图
基础教程推荐
猜你喜欢
- 详解c# Emit技术 2023-03-25
- C利用语言实现数据结构之队列 2022-11-22
- 一文带你了解C++中的字符替换方法 2023-07-20
- C++详细实现完整图书管理功能 2023-04-04
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C++中的atoi 函数简介 2023-01-05
- 如何C++使用模板特化功能 2023-03-05
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- C语言 structural body结构体详解用法 2022-12-06
- C/C++编程中const的使用详解 2023-03-26