chord chart 弦图

plot beautiful chord chart 好看的弦图绘制
738 download
Aggiornato 9 ago 2024

Visualizza la licenza

plot beautiful chord chart
好看的弦图绘制
详细使用请看demo
dataMat=[2 0 1 2 5 1 2;
3 5 1 4 2 0 1;
4 0 5 5 2 4 3];
dataMat=dataMat+rand(3,7);
dataMat(dataMat<1)=0;
colName={'G1','G2','G3','G4','G5','G6','G7'};
rowName={'S1','S2','S3'};
CC=chordChart(dataMat,'rowName',rowName,'colName',colName);
CC=CC.draw();
CC.setFont('FontSize',17,'FontName','Cambria')
% 显示刻度和数值
% Displays scales and numeric values
CC.tickState('on')
CC.tickLabelState('on')
% 调节标签半径
% Adjustable Label radius
CC.setLabelRadius(1.4);
另:公众号slandarer随笔将会进行此函数的详细说明
version 1.5.0
+ 修复了老版本 sum(....,[1,2])的bug
Fixed the bug of the old version(sum(....,[1,2]))
+ 增添了可调节方块间距的属性'Sep'
Added attribute 'Sep' with adjustable square spacing
+ 增添demo3 旋转标签角度示例
demo3 is added to show how to rotate the label
version 1.7.0
+ 增添了可调节标签半径的属性'LRadius'
Added attribute 'LRadius' with adjustable Label radius
+ 增添了可调节标签旋转的属性'LRotate'及函数 `labelRatato`(demo3)
Added attribute 'LRotate' and function `labelRatato` with adjustable Label rotate(demo3)
+ 可直接使用`colormap`函数调整颜色(demo4)
Colors can be adjusted directly using the function `colormap`(demo4)
+ 可使用函数`tickLabelState`显示刻度标签(demo5)
Use function `tickLabelState` to display tick labels(demo5)
version 2.1.0
+ 单独设置每一个弦末端方块(Set individual end blocks for each chord)
Use obj.setEachSquareT_Prop
or obj.setEachSquareF_Prop
F means from (blocks below)
T means to (blocks above)
rng(3)
dataMat = randi([1, 15], [7, 22]);
dataMat(dataMat < 11) = 0;
dataMat(1, sum(dataMat,1) == 0) = 15;
colName = {'A2M', 'FGA', 'FGB', 'FGG', 'F11', 'KLKB1', 'SERPINE1', 'VWF',...
'THBD', 'TFPI', 'PLAT', 'SERPINA5', 'SERPIND1', 'F2', 'PLG', 'F12',...
'SERPINC1', 'SERPINA1', 'PROS1', 'SERPINF2', 'F13A1', 'PROC'};
rowName = {'Lung', 'Spleen', 'Liver', 'Heart',...
'Renal cortex', 'Renal medulla', 'Thyroid'};
figure('Units','normalized', 'Position',[.02, .05, .6, .85])
CC = chordChart(dataMat, 'rowName',rowName, 'colName',colName, 'Sep',1/80, 'LRadius',1.21);
CC = CC.draw();
CC.labelRotate('on')
% 单独设置每一个弦末端方块(Set individual end blocks for each chord)
% Use obj.setEachSquareT_Prop
% or obj.setEachSquareF_Prop
% F means from (blocks below)
% T means to (blocks above)
CListT = [173,70,65; 79,135,136]./255;
% Upregulated:1 | Downregulated:2
Regulated = rand([7, 22]);
Regulated = (Regulated < .8) + 1;
for i = 1:size(Regulated, 1)
for j = 1:size(Regulated, 2)
CC.setEachSquareT_Prop(i, j, 'FaceColor', CListT(Regulated(i,j),:))
end
end
% 绘制图例(Draw legend)
H1 = fill([0,1,0]+100, [1,0,1]+100, CListT(1,:), 'EdgeColor','none');
H2 = fill([0,1,0]+100, [1,0,1]+100, CListT(2,:), 'EdgeColor','none');
lgdHdl = legend([H1,H2], {'Upregulated','Downregulated'}, 'AutoUpdate','off', 'Location','best');
lgdHdl.ItemTokenSize = [12,12];
lgdHdl.Box = 'off';
lgdHdl.FontSize = 13;
% 修改下方方块颜色(Modify the color of the blocks below)
CListF=[128,108,171; 222,208,161; 180,196,229; 209,150,146; 175,201,166;
134,156,118; 175,175,173]./255;
for i=1:7
CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
for i=1:7
for j=1:22
CC.setChordMN(i,j, 'FaceColor',CListF(i,:), 'FaceAlpha',.45)
end
end
version 2.2.0
+ 可使用`SSqRatio`属性调整弦末端弧形块占比
The 'SSqRatio' attribute can be used to adjust
the ratio of arc-shaped blocks at the end of the chord
dataMat = rand([11,4]);
dataMat = round(10.*dataMat.*((11:-1:1).'+1))./10;
colName = {'A','B','C','D'};
rowName = {'Acidobacteriota', 'Actinobacteriota', 'Proteobacteria', ...
'Chloroflexi', 'Bacteroidota', 'Firmicutes', 'Gemmatimonadota', ...
'Verrucomicrobiota', 'Patescibacteria', 'Planctomyetota', 'Others'};
figure('Units','normalized', 'Position',[.02,.05,.8,.85])
CC = chordChart(dataMat, 'colName',colName, 'Sep',1/80, 'SSqRatio',30/100);
CC = CC.draw();
% 修改上方方块颜色(Modify the color of the blocks above)
CListT = [0.93,0.60,0.62
0.55,0.80,0.99
0.95,0.82,0.18
1.00,0.81,0.91];
for i = 1:size(dataMat, 2)
CC.setSquareT_N(i, 'FaceColor',CListT(i,:))
end
% 修改下方方块颜色(Modify the color of the blocks below)
CListF = [0.75,0.73,0.86
0.56,0.83,0.78
0.00,0.60,0.20
1.00,0.49,0.02
0.78,0.77,0.95
0.59,0.24,0.36
0.98,0.51,0.45
0.96,0.55,0.75
0.47,0.71,0.84
0.65,0.35,0.16
0.40,0.00,0.64];
for i = 1:size(dataMat, 1)
CC.setSquareF_N(i, 'FaceColor',CListF(i,:))
end
% 修改弦颜色(Modify chord color)
CListC = [0.55,0.83,0.76
0.75,0.73,0.86
0.00,0.60,0.19
1.00,0.51,0.04];
for i = 1:size(dataMat, 1)
for j = 1:size(dataMat, 2)
CC.setChordMN(i,j, 'FaceColor',CListC(j,:), 'FaceAlpha',.4)
end
end
% 单独设置每一个弦末端方块(Set individual end blocks for each chord)
% Use obj.setEachSquareF_Prop
% or obj.setEachSquareT_Prop
% F means from (blocks below)
% T means to (blocks above)
for i = 1:size(dataMat, 1)
for j = 1:size(dataMat, 2)
CC.setEachSquareT_Prop(i,j, 'FaceColor', CListF(i,:))
end
end
% 添加刻度
CC.tickState('on')
% 修改字体,字号及颜色
CC.setFont('FontName','Cambria', 'FontSize',17)
% 隐藏下方标签
textHdl = findobj(gca, 'Tag','ChordLabel');
for i = 1:length(textHdl)
if textHdl(i).Position(2) < 0
set(textHdl(i), 'Visible','off')
end
end
% 绘制图例(Draw legend)
scatterHdl = scatter(10.*ones(size(dataMat,1)),10.*ones(size(dataMat,1)), ...
55, 'filled');
for i = 1:length(scatterHdl)
scatterHdl(i).CData = CListF(i,:);
end
lgdHdl = legend(scatterHdl, rowName, 'Location','best', 'FontSize',16, 'FontName','Cambria', 'Box','off');
set(lgdHdl, 'Position',[.7482,.3577,.1658,.3254])

Cita come

Zhaoxu Liu / slandarer (2024). chord chart 弦图 (https://www.mathworks.com/matlabcentral/fileexchange/116550-chord-chart), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2022a
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versione Pubblicato Note della release
3.1.0

support R2018b

3.0.0

+ 新增两种标志刻度的方法
Added 2 methods to adjust ticks
try : CC = chordChart(..., 'TickMode','auto', ...)

+ 'value' : default

+ 'auto' : 当有刻度离得很近的时候,绘制斜线将其距离拉远
When there are scales that are very close, draw a diagonal line

2.2.0

+ 可使用`SSqRatio`属性调整弦末端弧形块占比
The 'SSqRatio' attribute can be used to adjust
the ratio of arc-shaped blocks at the end of the chord

2.1.1

修复了老版本部分标签错误旋转的bug
Fixed a bug with incorrect rotation of some labels in older versions

2.1.0

+ 单独设置每一个弦末端方块(Set individual end blocks for each chord)
Use obj.setEachSquareT_Prop
or obj.setEachSquareF_Prop
F means from (blocks below)
T means to (blocks above)

1.7.4

add Copyright

1.7.3

Adjust numeric string format

1.7.2

fix labelRotate

1.7.1

add function setTickFont

1.7.0

Added attribute 'LRadius' with adjustable Label radius
Added attribute 'LRotate' and function `labelRatato` with adjustable Label rotate
Colors can be adjusted directly using the function `colormap`
Use function `tickLabelState` to disp tick labels

1.6.0

修复了老版本 sum(....,[1,2])的bug
Fixed the bug of the old version(sum(....,[1,2]))
增添了可调节方块间距的属性'Sep'
Added attribute 'Sep' with adjustable square spacing
增添demo3 旋转标签角度示例
demo3 is added to show how to rotate the label

对1.5.0的间距控制做了调整

1.5.0

修复了老版本 sum(....,[1,2])的bug
Fixed the bug of the old version(sum(....,[1,2]))
增添了可调节方块间距的属性'Sep'
Added attribute 'Sep' with adjustable square spacing
增添demo3 旋转标签角度示例
demo3 is added to show how to rotate the label

1.0.0