Make a pie chart map

12 次查看(过去 30 天)
Trevor King
Trevor King 2017-9-27
评论: Umar 2024-8-1,8:01
The code below plots circles on a map, the size of which is proportional to the sum of 3 quantities (see attached image). I would like to make a map that has a pie-chart at each location for the relative portions of A, B & C ... and still have the size of the circle proportional to the sum of 3 quantities.
% PieChartMap_test.m
%%Create data.
Name = {'London', 'Edinburgh', 'Amsterdam', 'Paris', 'Rome'};
Lat = [51.508530, 55.953251, 52.379189, 48.864716, 41.890251];
Lon = [-0.076132, -3.188267, 4.899431, 2.349014, 12.492373];
A = [3,7,5,1,8];
B = [1,7,9,5,7];
C = [2,6,8,2,7];
Total = A + B + C;
%%Scale data so you can see circles on map.
maxCircleSize = 2000;
Total_forMapCircles = maxCircleSize * (Total/max(Total));
%%Make map with circle size proportional to Total.
load coastlines
LatLim = [min(Lat)-2 max(Lat)+2];
LonLim = [min(Lon)-2 max(Lon)+2];
worldmap(LatLim, LonLim)
coast = plotm(coastlat, coastlon);
scatterm(Lat,Lon,Total_forMapCircles,[0.5 0.5 0.5],'filled')

回答(1 个)

Chad Greene
Chad Greene 2017-9-27
Edward Tufte says the only thing worse than a pie chart is several of them. Also, by "size of the circle" do you mean its radius or area? The radius of a circle does not scale linearly with its area, so which represents the data? Further complicating things, humans do not perceive the size of a circle linearly with its radius or its area. With an uncertain transfer function between the "size of the circle" and the data it represents, you lose the quantitative nature of your data.
The idea of multiple pie charts of various size on a map makes me cringe for those reasons. Also it often feels like trying to pile in too much information in the same field of view, and the big picture most often gets lost because it's not natural or intuitive to understand how it all goes together. It tasks the viewer with meticulous work of trying to relate the size of a pink slice of pie over Hamburg to the blue slice over Venice. And then it's still not clear what exactly the size means, quantitatively. However, if you really want to go down this route, you might consider using pie with mfwdtran something like this:
X = [1 3 0.5 2.5 2];
p=pie(X);
p(1).Vertices
sc = 0.001; % <scaling factor (different for each city)
% Loop through each slice of the pie:
for k = 1:2:length(p)
% x,y coordinates of a slice:
tmp = p(k).Vertices;
% Scale the size of the slice:
tmp = tmp*sc;
[x0,y0] = mfwdtran(lat,lon); % <geocoordinates of the city
% Place the center of the pie on its city:
tmp(:,1) = tmp(:,1)+x0;
tmp(:,2) = tmp(:,2)+x0;
patch(tmp(:,1),tmp(:,2),'b') % <-specify the color you want
end
  2 个评论
Patrick Anderson
Patrick Anderson 2021-8-31
"Edward Tufte says the only thing worse than a pie chart is several of them. "
I wanted to thank the author for a little bit of humor on the topic of visualizing quantitative information. The world needs more of that.
PLA
Umar
Umar 2024-8-1,8:01

@Trevor King,

Your problem doesn’t sound like , ““Houston, we've had a problem” , so to achieve the desired outcome of displaying pie charts on a map with proportional circle sizes, you need to make several modifications to the existing code. I will integrate pie charts into the map visualization to represent the relative contributions of A, B, and C at each location. Here is the updated Matlab code that includes pie charts on the map:

% PieChartMap_Pie.m

%% Create data.

Name = {'London', 'Edinburgh', 'Amsterdam', 'Paris', 'Rome'};

Lat = [51.508530, 55.953251, 52.379189, 48.864716, 41.890251];

Lon = [-0.076132, -3.188267, 4.899431, 2.349014, 12.492373];

A = [3, 7, 5, 1, 8];

B = [1, 7, 9, 5, 7];

C = [2, 6, 8, 2, 7];

Total = A + B + C;

%% Scale data for circle sizes on the map.

maxCircleSize = 2000;

Total_forMapCircles = maxCircleSize * (Total / max(Total));

%% Create map with circles and pie charts.

figure;

worldmap('World');

load coastlines;

plotm(coastlat, coastlon);

for i = 1:numel(Lat)

    [x, y] = mfwdtran(Lat(i), Lon(i));
    subplot('Position', [x/1e6, y/1e6, 0.1, 0.1]);
    pie([A(i), B(i), C(i)], Name{i});

end

scatterm(Lat, Lon, Total_forMapCircles, [0.5 0.5 0.5], 'filled');

So, in the above modified code, a new figure is created for the map visualization and then iterating over each location and plot a pie chart at the corresponding map coordinates. The subplot function is used to position the pie charts at the correct locations on the map and the pie function is employed to create pie charts representing the relative proportions of A, B, and C at each location. Finally, retaining the scatter plot with circle sizes proportional to the total of the three quantities. Hope, this answers your question.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Pie Charts 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by