Creating a polar bar chart or circumplex chart (not a histogram)

66 ビュー (過去 30 日間)
CH_NewCoder
CH_NewCoder 2022 年 7 月 1 日
コメント済み: Jon 2022 年 7 月 5 日
I’m trying to create a polar bar chart (or circumplex chart) similar to the one created in R by Conor McLaughlin at https://conormclaughlin.net/2018/07/creating-circumplex-polar-bar-charts-in-r-with-ggplot2/
Essentially, I’m trying to plot a bar chart and then convert it to a polar coordinate system. I’ve tried using polarhistogram and rose, but both appear to bin the data and create a histogram, rather than plotting the raw data in each pre-existing group.
Is there a way to use bar to create a bar chart and then change the coordinates to polar? Or is there a way to make sure polarhistogram only plots raw data without doing statistics?
Thanks!
P.S. My data looks something like this, with four groups showing different soil particle size classes and percentage of the total concentration of a given metal associated with each size class.
Particle Size Class Percent of total concentration
A 10
B 15
C 60
D 15

採用された回答

Adam Danz
Adam Danz 2022 年 7 月 1 日
編集済み: Adam Danz 2022 年 7 月 1 日
If you have data suitable for a bar plot and, therefore, you don't need to compute the bins and bar heights, see polarhistogram('BinEdges',edges,'BinCounts',counts)
Since polarhistogram only allows setting a uniform color, a workaround is to plot each segement in a loop. That will require computing the bin counts ahead of time.
I've changed the face and edge colors and the transparency level to match the OP's sample image but I recommend removing the FaceAlpha line so you can make use of the polar grid.
theta = [0.1 1.1 5.4 3.4 2.3 4.5 3.2 3.4 5.6 2.3 2.1 3.5 0.6 6.1];
nbins = 6;
thetaBins = linspace(0,2*pi,nbins+1);
counts = histcounts(theta, thetaBins);
figure
tcl = tiledlayout(1,2);
nexttile(tcl)
polarhistogram(theta,nbins)
title('polarhistogram')
pax = polaraxes(tcl);
pax.Layout.Tile = 2;
hold(pax,'on')
faceColor = turbo(nbins); % choose your face colors
for i = 1:numel(counts)
polarhistogram(pax,'BinEdges',thetaBins(i:i+1),'BinCounts',counts(i), ...
'FaceColor', faceColor(i,:), ...
'FaceAlpha', 1, ... % to match image in OP's question
'EdgeColor','w') % to match image in OP's question
end
title('loop')
  3 件のコメント
Adam Danz
Adam Danz 2022 年 7 月 1 日
編集済み: Adam Danz 2022 年 7 月 1 日
> Looks like you can only set one color for all of the bins.
Indeed.
A workaround is to plot each segement in a loop. I'll add a demo to the answer for better visibility.
Jon
Jon 2022 年 7 月 5 日
@Adam Danz - very nice, thorough example

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by