如何用带孔的ggplot绘制地图

时间:2017-06-05 11:36:18

标签: r ggplot2 geospatial shapefile choropleth

我想创建一个欧洲的等值线,为每个分类变量分配一个颜色。为此,我使用了Eurostat提供的多边形shapefile。代码如下,EU_spat是多边形shapefile。

EU_data = fortify(EU_spat, region = "NUTS_ID") 
EU_clusters = merge(EU_data, cluster_data1, by.x = "id", by.y = "GEO")

    ggplot(EU_clusters)+
  theme_minimal()+
  geom_polygon(aes(x = long, y = lat, group=group, fill=clusters), color = "grey") +
  scale_x_continuous(limits = c(-30, 50)) +
  scale_y_continuous(limits = c(25, 75)) +
  scale_fill_manual("", values = c("outlier" = "grey", "positive" = "red", "negative" = "blue")) 

然而,在运行此代码时,一些白色表面(孔)看起来与下面链接提供的荷兰图相当。

https://i2.wp.com/rmhogervorst.nl/cleancode/images/figures/unnamed-chunk-5-1.png?zoom=1.5&w=456

我尝试使用coord_map()和coord_fixed(),但白洞并没有消失。

有谁知道如何解决这个问题?

*修改

clusterdata具有以下形式。 (因为它是一个大数据帧,我不能提供整个数据帧)

         id         long        lat  order  hole piece    group clusters
1      AT11  16.73979750  47.695251     57 FALSE     1   AT11.1 negative
2      AT11  16.74850650  47.682202     56 FALSE     1   AT11.1 negative
3      AT11  16.65601900  47.741655     61 FALSE     1   AT11.1 negative
4      AT11  16.72151400  47.722600     58 FALSE     1   AT11.1 negative
5      AT11  16.72094200  47.735335     59 FALSE     1   AT11.1 negative
6      AT11  16.66996350  47.740776     60 FALSE     1   AT11.1 negative
7      AT11  16.85552100  47.711065     52 FALSE     1   AT11.1 negative
8      AT11  16.83906450  47.704570     53 FALSE     1   AT11.1 negative
9      AT11  16.82833250  47.682722     54 FALSE     1   AT11.1 negative
10     AT11  16.74903100  47.681416     55 FALSE     1   AT11.1 negative
11     AT11  16.59094950  47.757962     69 FALSE     1   AT11.1 negative
12     AT11  16.56646150  47.751578     70 FALSE     1   AT11.1 negative
13     AT11  16.54797900  47.751539     71 FALSE     1   AT11.1 negative
14     AT11  16.54596250  47.749317     72 FALSE     1   AT11.1 negative
15     AT11  16.54878500  47.743171     73 FALSE     1   AT11.1 negative
16     AT11  16.54272300  47.742346     74 FALSE     1   AT11.1 negative
17     AT11  16.63971750  47.748269     62 FALSE     1   AT11.1 negative
18     AT11  16.63836950  47.754549     63 FALSE     1   AT11.1 negative
19     AT11  16.63426350  47.759053     64 FALSE     1   AT11.1 negative
20     AT11  16.62213200  47.757241     65 FALSE     1   AT11.1 negative
21     AT11  16.61228950  47.760227     66 FALSE     1   AT11.1 negative
22     AT11  16.59877350  47.756120     67 FALSE     1   AT11.1 negative
23     AT11  16.59410650  47.758576     68 FALSE     1   AT11.1 negative
24     AT11  17.07455750  48.085921      1 FALSE     1   AT11.1 negative
25     AT11  17.07155200  48.080931      2 FALSE     1   AT11.1 negative
26     AT11  17.07222950  48.070456      3 FALSE     1   AT11.1 negative
27     AT11  17.08678800  48.065366      4 FALSE     1   AT11.1 negative
28     AT11  17.07016200  48.057012      5 FALSE     1   AT11.1 negative
29     AT11  17.06824150  48.055402      6 FALSE     1   AT11.1 negative
30     AT11  17.08426600  48.050392      7 FALSE     1   AT11.1 negative
31     AT11  17.08778650  48.045685      8 FALSE     1   AT11.1 negative
32     AT11  17.06741450  48.031438      9 FALSE     1   AT11.1 negative
33     AT11  17.07562600  48.027550     10 FALSE     1   AT11.1 negative
34     AT11  17.08985750  48.019793     11 FALSE     1   AT11.1 negative
35     AT11  17.11005350  48.031233     12 FALSE     1   AT11.1 negative
36     AT11  17.11500800  48.029624     13 FALSE     1   AT11.1 negative
37     AT11  17.12672300  48.020936     14 FALSE     1   AT11.1 negative
38     AT11  17.13637350  48.022920     15 FALSE     1   AT11.1 negative
39     AT11  17.14384350  48.020188     16 FALSE     1   AT11.1 negative
40     AT11  17.16079750  48.006656     17 FALSE     1   AT11.1 negative
41     AT11  17.09466150  47.970872     18 FALSE     1   AT11.1 negative
42     AT11  17.11689000  47.960952     19 FALSE     1   AT11.1 negative
43     AT11  17.09090550  47.934385     20 FALSE     1   AT11.1 negative
44     AT11  17.11269000  47.927351     21 FALSE     1   AT11.1 negative
45     AT11  17.10274700  47.910455     22 FALSE     1   AT11.1 negative
46     AT11  17.10417150  47.899251     23 FALSE     1   AT11.1 negative
47     AT11  17.08518750  47.874437     24 FALSE     1   AT11.1 negative
48     AT11  17.07779950  47.877547     25 FALSE     1   AT11.1 negative
49     AT11  17.06270200  47.873711     26 FALSE     1   AT11.1 negative
50     AT11  17.04870850  47.871899     27 FALSE     1   AT11.1 negative
51     AT11  17.04959850  47.870060     28 FALSE     1   AT11.1 negative
52     AT11  17.04004300  47.866809     29 FALSE     1   AT11.1 negative
53     AT11  17.01775450  47.868397     30 FALSE     1   AT11.1 negative
54     AT11  17.00994950  47.858344     31 FALSE     1   AT11.1 negative
55     AT11  17.05154300  47.837894     32 FALSE     1   AT11.1 negative
56     AT11  17.04972300  47.831216     33 FALSE     1   AT11.1 negative
57     AT11  17.04691350  47.828352     34 FALSE     1   AT11.1 negative
58     AT11  17.05973250  47.820152     35 FALSE     1   AT11.1 negative
59     AT11  17.07445350  47.808256     36 FALSE     1   AT11.1 negative
60     AT11  17.05096200  47.793974     37 FALSE     1   AT11.1 negative
61     AT11  17.05819600  47.786153     38 FALSE     1   AT11.1 negative
62     AT11  17.06379550  47.777811     39 FALSE     1   AT11.1 negative
63     AT11  17.06699100  47.767498     40 FALSE     1   AT11.1 negative
64     AT11  17.07076450  47.749943     41 FALSE     1   AT11.1 negative
65     AT11  17.07027050  47.728197     42 FALSE     1   AT11.1 negative
66     AT11  17.09307400  47.708236     43 FALSE     1   AT11.1 negative
67     AT11  17.07126650  47.706652     44 FALSE     1   AT11.1 negative
68     AT11  17.04014150  47.704324     45 FALSE     1   AT11.1 negative
69     AT11  17.00113600  47.698292     46 FALSE     1   AT11.1 negative
70     AT11  16.95933000  47.692710     47 FALSE     1   AT11.1 negative
71     AT11  16.91254100  47.687677     48 FALSE     1   AT11.1 negative
72     AT11  16.87163500  47.690096     49 FALSE     1   AT11.1 negative
73     AT11  16.86882350  47.721336     50 FALSE     1   AT11.1 negative
74     AT11  16.86690400  47.721643     51 FALSE     1   AT11.1 negative
75     AT11  16.11285250  46.979489    294 FALSE     1   AT11.1 negative
76     AT11  16.12171950  46.990667    295 FALSE     1   AT11.1 negative
77     AT11  16.13640500  46.994648    296 FALSE     1   AT11.1 negative
78     AT11  16.15452950  46.990814    297 FALSE     1   AT11.1 negative
79     AT11  16.14559950  46.999800    298 FALSE     1   AT11.1 negative
80     AT11  16.13702650  47.006940    299 FALSE     1   AT11.1 negative
81     AT11  16.14011250  47.009082    300 FALSE     1   AT11.1 negative
82     AT11  16.13072750  47.012126    301 FALSE     1   AT11.1 negative
83     AT11  16.12829178  47.014944    302 FALSE     1   AT11.1 negative
84     AT11  16.12601024  47.017584    303 FALSE     1   AT11.1 negative
85     AT11  16.12497610  47.018780    304 FALSE     1   AT11.1 negative
86     AT11  16.12476150  47.018896    305 FALSE     1   AT11.1 negative
87     AT11  16.12473568  47.019059    306 FALSE     1   AT11.1 negative
88     AT11  16.12462238  47.019190    307 FALSE     1   AT11.1 negative
89     AT11  16.11657800  47.028499    308 FALSE     1   AT11.1 negative
90     AT11  16.11445242  47.031751    309 FALSE     1   AT11.1 negative
91     AT11  16.11438000  47.035281    310 FALSE     1   AT11.1 negative
92     AT11  16.12108650  47.041856    311 FALSE     1   AT11.1 negative
93     AT11  16.12107800  47.044727    312 FALSE     1   AT11.1 negative
94     AT11  16.11124300  47.048803    313 FALSE     1   AT11.1 negative
95     AT11  16.10467750  47.060757    314 FALSE     1   AT11.1 negative
96     AT11  16.09686000  47.058988    315 FALSE     1   AT11.1 negative
97     AT11  16.09836300  47.061067    316 FALSE     1   AT11.1 negative
98     AT11  16.08862900  47.072079    317 FALSE     1   AT11.1 negative
99     AT11  16.08650800  47.074209    318 FALSE     1   AT11.1 negative
100    AT11  16.09028900  47.082312    319 FALSE     1   AT11.1 negative
101    AT11  16.08657950  47.087840    320 FALSE     1   AT11.1 negative
102    AT11  16.09200450  47.090646    321 FALSE     1   AT11.1 negative
103    AT11  16.09143900  47.101678    322 FALSE     1   AT11.1 negative
104    AT11  16.09357750  47.108916    323 FALSE     1   AT11.1 negative
105    AT11  16.09479350  47.112201    324 FALSE     1   AT11.1 negative
106    AT11  16.10395650  47.114059    325 FALSE     1   AT11.1 negative
107    AT11  16.10909550  47.126886    326 FALSE     1   AT11.1 negative
108    AT11  16.11502500  47.133192    327 FALSE     1   AT11.1 negative
109    AT11  16.11245850  47.141044    328 FALSE     1   AT11.1 negative
110    AT11  16.11688450  47.143933    329 FALSE     1   AT11.1 negative
111    AT11  16.11346300  47.161839    330 FALSE     1   AT11.1 negative
112    AT11  16.10915050  47.166379    331 FALSE     1   AT11.1 negative
113    AT11  16.10928650  47.166786    332 FALSE     1   AT11.1 negative
114    AT11  16.10258100  47.183651    333 FALSE     1   AT11.1 negative
115    AT11  16.09463600  47.197177    334 FALSE     1   AT11.1 negative
116    AT11  16.09149700  47.198464    335 FALSE     1   AT11.1 negative
117    AT11  16.09280150  47.199911    336 FALSE     1   AT11.1 negative
118    AT11  16.09098850  47.209185    337 FALSE     1   AT11.1 negative
119    AT11  16.08558550  47.211223    338 FALSE     1   AT11.1 negative
120    AT11  16.08241200  47.226759    339 FALSE     1   AT11.1 negative
121    AT11  16.08475850  47.231954    340 FALSE     1   AT11.1 negative
122    AT11  16.08652150  47.233542    341 FALSE     1   AT11.1 negative
123    AT11  16.08445550  47.235413    342 FALSE     1   AT11.1 negative
124    AT11  16.08483000  47.247203    343 FALSE     1   AT11.1 negative
125    AT11  16.07758450  47.272128    344 FALSE     1   AT11.1 negative
[ reached getOption("max.print") -- omitted 290284 rows ]

0 个答案:

没有答案