2014-01-15 103 views
2

我有以下几点:鸿沟世界地图到特定国家/地区的面板

> dd 
      area   Lon  Lat 
1 2530000.00 -84.744000 39.57500 
2 5300000.00 -3.200000 54.66000 
3  100000.00 -2.970000 54.40000 
4  10632.91 -89.494500 46.23046 
5  190000.00 -2.923600 54.50630 
6  239000.00 -3.260200 54.42850 
7  930000.00 -3.264400 54.53120 
8  223045.80 12.303000 55.93400 
9 3236000.00 -3.691800 52.94930 
10  94000.00 -3.028400 56.49910 
11 4700000.00 -3.075300 54.33810 
12 400000.00 -3.819200 52.99930 
13 258924.72 -89.473300 46.21046 
14 340000.00 -89.612000 46.00200 
15  5524.00 -89.606000 46.00800 
16  57000.00 -3.962000 52.79470 
17 170000.00 -3.025900 54.42720 
18 3000000.00 -3.381200 54.52220 
19 23674200.00 18.587000 59.84600 
20 1000000.00 -2.990000 54.36000 
21 140000.00 -3.990100 57.54240 
22 110000.00 9.452022 56.01752 
23 640000.00 -3.019500 54.44840 
24 100285.00 12.303000 55.98500 
25 664549.00 9.391000 56.02000 
26 1513724.00 -79.135600 45.37960 
27  7862.06 -89.505900 46.24369 
28 60900000.00 10.070000 45.72400 
29 163268000.00 35.588000 32.81700 
30  2468.00 -89.678000 45.99500 
31  51000.00 -85.349000 42.41100 
32  51000.00 -4.041800 53.01420 
33 1057000.00 -4.546000 56.21300 
34  93000.00 -5.429600 57.49210 
35 1114000.00 -4.281000 55.00210 
36  99000.00 -3.321500 56.95920 
37 111000.00 -4.509200 56.22730 
38 71000000.00 -4.616000 56.10500 
39 600000.00 -3.350000 54.58000 
40 38282400.00 -89.424000 43.10500 
41  58818.50 -89.521300 46.25745 
42  37833.00 -89.722000 45.99800 
43  4624.00 -89.705000 46.00500 
44 970000.00 -4.131900 53.12800 
45  3000.00   NA  NA 
46  10000.00 -2.990800 54.37210 
47 127000.00 -4.430400 55.09330 
48 79855500.00 176.267000 -38.08200 
49 34600000.00 176.419000 -38.03700 
50 500000.00 -2.386400 53.35400 
51 19800000.00 -122.094000 47.60000 
52  35500.00 -5.448100 57.27850 
53 100500.00 -5.445000 57.59120 
54  96400.00 -5.392200 57.51680 
55  14400.00 -5.305400 57.25070 
56  16400.00 -5.103700 57.17190 
57 311000.00 -5.024400 57.71260 
58  75500.00 -4.954900 57.49550 
59  53600.00 -4.936500 57.45240 
60 216100.00 -4.954400 57.68130 
61  56000.00 -4.935600 57.80980 
62 144600.00 -3.538200 56.88500 
63  43000.00 -3.299100 54.48120 
64 14918400.00 -89.672000 46.02900 
65 618453.00 -89.700000 46.00800 
66 820000.00 -4.031300 55.79300 
67 4100000.00 3.630000 52.88000 
68  566.00 -89.431000 46.00300 
69  10478.00 -89.686000 46.04100 
70 8900000.00 -2.889000 54.57610 
71 2350000.00 -122.335100 47.63900 
72 54000000.00 177.088000 -38.76800 
73 88000000.00 -122.257000 47.61800 
74  48657.67 -89.502830 46.23562 
75 6700000.00 -2.930000 54.35000 
76 1300000.00 -89.417800 43.05370 
77 164000.00 -85.383000 42.39800 

,我已经产生这些问题的一个世界地图:

library(ggplot2) 
library(maps) 
mdat <- map_data('world') 

str(mdat) 
ggplot() + 
    geom_polygon(dat=mdat, aes(long, lat, group=group), fill="grey50") + 
    geom_point(data=dd, 
      aes(x = Lon, y = Lat, size=`area`), col="red") 

导致:

enter image description here

然而,从这里,我可以看到6个不同的r太平洋:
1.华盛顿2.大湖区3.英国。 4.新西兰5.欧洲其他地区。 6.以色列

将此地图分成6个区域以更好地展示区域的最佳方式是什么?请注意,红色的圆圈表示特定变量的不同大小,我希望大小能够在面板之间传输,即不是每个面板的独立图例。

我最终希望生产的东西像

enter image description here

虽然每个小组应该代表世界不同地区,上述规定。

+0

这听起来有点像刻划自由秤,但我不知道你是否可以用地图做到这一点? – CMichael

回答

2

不幸的是,由于地图上的自由标尺ggplot不起作用。我不知道任何方式来手动指定每个面尺度,因此有三种可能的解决方案:

  1. 只问ggplot绘制你感兴趣的领域这是艰苦的,但工程(见这里的解决方案)
  2. 做多的ggplot地块的区域循环和手动指定秤,然后重新组装(或者与grid或手动)
  3. 最优雅的将是获取地图数据,然后“俗套它”只留下你想要的区域,适当关闭多边形。

虽然3会更好,该算法的cookie cuttering可能会带我不是上面的hackish的#1解决方案更长的时间,所以这里是#1:

library(ggplot2) 
library(maps) 
df <- df[complete.cases(df),] 
df$dist.london <- sqrt((df$Lat - 51.5)^2 + (df$Lon - 0.1275)^2) 
df$rg <- cut(df$dist.london, c(0, 10, 35, 65, 100, 150, 300), include.lowest=T) 
levels(df$rg) <- c("UK", "RoE", "Israel", "Midwest", "US West", "New Zealand") 

RoE <- c("France", "Germany", "Denmark", "Spain", "Italy", "Belgium", "Netherlands") 
West <- tolower(c("Washington", "Oregon", "California", "Nevada", "Idaho")) 
Lakes <- tolower(c("Michigan", "Illinois", "Wisconsin", "Indiana", "Ohio", "New York")) 
mdat <- rbind(
    map_data('world', c("UK", RoE, "Israel", "New Zealand")), 
    map_data("state", c(West, Lakes)) 
) 
reg.map <- rbind(
    cbind(RoE, "RoE"), 
    cbind(West, "US West"), 
    cbind(Lakes, "Midwest"), 
    cbind("UK", "UK"), 
    cbind("Israel", "Israel"), 
    cbind("New Zealand", "New Zealand") 
) 
mdat$rg <- factor(reg.map[match(mdat$region, reg.map[, 1]), 2], levels=levels(df$rg)) 
mdat <- subset(mdat, !(rg == "RoE" & (lat < 35 | long < -20))) 
mdat <- subset(mdat, !(rg == "UK" & (lat < 50 | long < -20))) 
mdat <- subset(mdat, !(rg == "New Zealand" & (lat > -20 | long < 100))) 

ggplot(data=df) + 
    geom_polygon(dat=mdat, aes(long, lat, group=group), fill="grey50", color="grey10") + 
    geom_point(aes(x = Lon, y = Lat, size=`area`), col="red") + 
    facet_wrap(~ rg, scales="free") 

enter image description here

我对大湖区和RoE很懒,但你明白了。