1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

地図上にバブルチャートを重ねて表示する方法

Last updated at Posted at 2023-07-24

はじめに

最近,地図上にバブルチャートを重ねて表示するグラフをPPT資料で見かける機会が増えました.愚直に円を挿入し,グラフに重ねている訳ではないのでしょうが,素朴にこのようなグラフをどのように作成しているのかが気になり,作り方について纏めました.

データの準備

地図上にバブルチャートを重ねて表示する方法について調べたところ,MATLABの「geoscatter」コマンドを用いれば作成できそうです.

このコマンドを適用するには,出力する地図座標の緯度・経度情報が必要になります.そこで,webページのhtmlファイルから緯度・経度の情報を抽出します.今回は例として,アメリカ50州の緯度経度情報を抽出します.下記のURLから情報を抽出しました.

今回は,アメリカの各州の人口のデータを取得し,バブルチャートとして出力します.下記のURLから人口の情報を取得しました.

実装結果

%% Load lattitude and longtitude of each state of US
Data = readtable("https://www.latlong.net/category/states-236-14.html",...
            FileType="html",ReadVariableNames=true,ThousandsSeparator=",");

%% Load Population of each state of US
T = readtable("https://www.statsamerica.org/sip/rank_list.aspx?rank_label=pop1",...
            FileType="html",ReadVariableNames=true,ThousandsSeparator=",");

%% Delete excess characters
Data.("Place Name") = erase(Data.("Place Name"),', USA');
Data.("Place Name") = erase(Data.("Place Name"),', the USA');
Data.("Place Name") = erase(Data.("Place Name"),', the US');

%
lat  = Data.Latitude;
long = Data.Longitude;

%% Create a single table of latitude and longitude and population for each state
[column_Data ,row_Data] = size(Data);
[column_T ,row_T] = size(T);
Data.Population = zeros(column_Data,1);
for i=1:1:column_Data
    for j = 1:1:column_T
        if Data.("Place Name")(i) == T.State(j)
            Data.Population(i) = T.Population(j);
        end
    end
end

%% Define bubble_size
m = max(Data.Population);
bubble_size = 500*Data.Population/m;

%% Output scatter plots of geographic coordinates
geoscatter(lat,long,bubble_size,"filled");
geobasemap landcover

上記のスクリプトを実行したところ,次のバブルチャートが得られました.
geoplot.jpg

今回は,地図のベースマップを「land cover」にしましたが,ベースマップを変更することもできます.詳細は下記をご参照ください.

おわりに

最後まで読んで頂きありがとうございます.まだまだqiita初心者ですので,どんどん記事を投稿し,質の高い内容を共有できるように頑張ります!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?