首页 > 解决方案 > R中的制图不会像预期的那样扭曲国家

问题描述

我正在使用cartogramR 中的包来制作活语言的世界地图。国家地图来自Natural Earth,语言计数来自Ethnologue

w <- readOGR('.','ne_110m_admin_0_map_units')
L <- read.csv('languages.csv',sep='\t')
w$rank <- 1:nrow(w)
wl <- merge(w@data,L,by.x='ISO_A3',by.y='iso3',all.x=T)
wl <- wl[order(wl$rank),]
wl[is.na(wl$Live),'Live'] <- 1
w@data <- wl
w2 <- cartogram_cont(w,'Live',prepare='none')
plot(w2)

生活语言图表

我使用的数据在俄罗斯有 111 种生活语言,在中国有 299 种,几乎是三倍。但是,创建的地图仍然显示俄罗斯比中国大。

以下是每个国家的数据:

> w@data[order(w$NAME),c('NAME','Live')]
                        NAME Live
13               Afghanistan   41
15                   Albania    8
57                   Algeria   18
14                    Angola   45
19                Antarctica    1
17                 Argentina   24
18                   Armenia    8
21                 Australia  206
22                   Austria   14
23                Azerbaijan   18
30                   Bahamas    3
28                Bangladesh   41
32                   Belarus    4
25                   Belgium   11
33                    Belize    8
26                     Benin   55
37                    Bhutan   23
34                   Bolivia   43
31          Bosnia and Herz.    4
38                  Botswana   31
12              Bougainville    1
35                    Brazil  218
36                    Brunei   15
29                  Bulgaria   12
27              Burkina Faso   71
24                   Burundi    3
99                  Cambodia   27
45                  Cameroon  277
40                    Canada   96
39      Central African Rep.   72
161                     Chad  131
42                     Chile   11
43                     China  299
48                  Colombia   84
47                     Congo   62
49                Costa Rica   11
44             Côte d'Ivoire   85
82                   Croatia   15
50                      Cuba    3
51                    Cyprus    4
52                   Czechia   10
46           Dem. Rep. Congo  211
55                   Denmark    5
54                  Djibouti    5
56            Dominican Rep.    4
58                   Ecuador   24
59                     Egypt   15
152              El Salvador    5
2                    England    1
75                Eq. Guinea   14
60                   Eritrea   15
63                   Estonia    7
159                 eSwatini    5
64                  Ethiopia   88
67              Falkland Is.    1
66                      Fiji   10
65                   Finland   13
20    Fr. S. Antarctic Lands    1
68                    France   22
79             French Guiana   13
69                     Gabon   43
73                    Gambia   11
70                   Georgia   20
53                   Germany   25
71                     Ghana   81
76                    Greece   18
77                 Greenland    3
78                 Guatemala   27
72                    Guinea   36
74             Guinea-Bissau   23
80                    Guyana   16
83                     Haiti    4
81                  Honduras   10
84                   Hungary   17
90                   Iceland    2
86                     India  448
85                 Indonesia  707
88                      Iran   78
89                      Iraq   23
87                   Ireland    5
91                    Israel   34
92                     Italy   34
93                   Jamaica    4
95                     Japan   15
94                    Jordan   11
96                Kazakhstan   14
97                     Kenya   67
5                     Kosovo    1
101                   Kuwait    3
98                Kyrgyzstan    6
102                     Laos   83
110                   Latvia    7
103                  Lebanon    7
107                  Lesotho    5
104                  Liberia   31
105                    Libya    9
108                Lithuania   10
109               Luxembourg    4
115                Macedonia   10
113               Madagascar   14
122                   Malawi   17
123                 Malaysia  134
116                     Mali   68
121               Mauritania    7
114                   Mexico  287
112                  Moldova   10
119                 Mongolia   12
118               Montenegro    6
111                  Morocco   14
120               Mozambique   43
117                  Myanmar  118
4                  N. Cyprus    1
1                 N. Ireland    1
124                  Namibia   27
130                    Nepal  121
129              Netherlands   15
125            New Caledonia   38
131              New Zealand    4
128                Nicaragua   11
126                    Niger   23
127                  Nigeria  519
139              North Korea    1
6                     Norway    1
132                     Oman   17
133                 Pakistan   74
134                   Panama   15
7           Papua New Guinea    1
141                 Paraguay   23
135                     Peru   93
136              Philippines  183
137                   Poland   21
140                 Portugal    9
138              Puerto Rico    4
142                    Qatar    3
143                  Romania   23
144                   Russia  111
145                   Rwanda    3
154                 S. Sudan   69
146             Saudi Arabia    7
8                   Scotland    1
148                  Senegal   38
3                     Serbia    1
151             Sierra Leone   24
156                 Slovakia   11
157                 Slovenia    7
150              Solomon Is.   73
153                  Somalia   13
9                 Somaliland    1
181             South Africa   30
100              South Korea    3
62                     Spain   16
106                Sri Lanka    7
147                    Sudan   75
155                 Suriname   21
149             Svalbard Is.    1
158                   Sweden   15
41               Switzerland   12
160                    Syria   18
170                   Taiwan   22
164               Tajikistan   13
171                 Tanzania  125
163                 Thailand   71
166              Timor-Leste   20
162                     Togo   44
167      Trinidad and Tobago    7
168                  Tunisia    6
169                   Turkey   39
165             Turkmenistan    6
172                   Uganda   43
173                  Ukraine   22
16      United Arab Emirates   10
175 United States of America  219
174                  Uruguay    5
176               Uzbekistan   11
179                  Vanuatu  111
177                Venezuela   42
178                  Vietnam  109
61                 W. Sahara    3
10                     Wales    1
11                 West Bank    1
180                    Yemen   11
182                   Zambia   46
183                 Zimbabwe   22

我究竟做错了什么?

编辑

按照 FuzzyLeapfrog 的回答,我删除了 Antarctica 并将地图转换为 Robinson 投影。

w <- w[-grep('Antarctica',w$NAME),]
w1 <- spTransform(w,CRS('+proj=robin'))
w2 <- cartogram_cont(w1,'Live')
tom <- 1 - w$Live/max(w$Live) # tonality
plot(w,col=rgb(tom,tom,tom))
plot(w1,col=rgb(tom,tom,tom))
plot(w2,col=rgb(tom,tom,tom))

以下是三张图:墨卡托投影、罗宾逊投影、变形后。灰色调与现存语言的数量成正比(颜色越深,数量越大)。

墨卡托投影

罗宾逊投影

罗宾逊投影,变形

你不觉得俄罗斯还是比中国大,应该是中国的1/3吗?

编辑2

上面的 Natural Earth 地图是一个轻量级的 shapefile(.shp 只有 182 kB)。使用更详细的地图(.shp 6.5 MB),我得到了以下地图(罗宾逊投影和罗宾逊变形)。俄罗斯还是太大了!我想知道这个国家的原始大小是否会影响最终的形状(我认为它没有,但现在我认为它会影响)。可能有一个选项,以便原始大小不会影响最终结果?

详细的罗宾逊投影

详细罗宾逊变形

编辑3

我尝试了两个等面积投影,Mollweide 和 Lambert Cylindrical。下面是 Lambert 的结果,现在以红色显示,首先是投影图,然后是投影+变形图。越红,面积应该越大。但事实并非如此(只需将巴布亚新几内亚与澳大利亚进行比较)。

兰伯特等面积投影

兰伯特等面积投影 + 地图变形

我想知道package 中cartogram_cont的函数是否cartogram真的做了我认为它应该做的事情;帮助页面说它遵循“橡胶片失真算法(Dougenik et al. 1985)”。

标签: rcartogram

解决方案


不仅俄罗斯和中国的尺寸不合适,南极洲也一样。看起来您正在使用墨卡托投影。我建议转换世界地图数据并排除南极洲,例如在这篇博文中建议的那样:

library(dplyr) # data manipulation
[...]
world_map = ne_countries(returnclass = "sf")
world_map = world_map %>% 
    select(sovereignt) %>% 
    filter(sovereignt != "Antarctica") %>% 
    st_transform(world_map, crs = "+proj=robin")
[...]

使国家大小变形的是a)投影和b)您添加的权重(在您的情况下是语言的数量)。a) 的影响变得更小,例如通过缩小您查看的区域或使用等面积投影,如 Mollweide。


推荐阅读