Creating a polar bar chart or circumplex chart (not a histogram)
56 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
More Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!