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

56 views (last 30 days)
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

Accepted Answer

Adam Danz
Adam Danz on 1 Jul 2022
Edited: Adam Danz on 1 Jul 2022
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 Comments
Adam Danz
Adam Danz on 1 Jul 2022
Edited: Adam Danz on 1 Jul 2022
> 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!