在 R 中使用 ggplot 在日期线上绘制点

时间:2021-01-07 15:11:22

标签: r ggplot2 coordinates geom-point

我试图在 R 中的地图上绘制一些点,但只有一半显示出来。我想这可能与日期变更线有关。

我的样本数据:

sites
    longitude latitude
1        -136       53
2         140       33
3        -176       59
4        -138       47
5        -170       61
6         142       35
7        -128       45
8        -178       55
9        -140       57
10       -168       39
11        158       39
12       -178       45
13        144       45
14       -166       25
15        162       47
16       -178       35
17       -178       43
18        146       39
19        138       25
20       -178       25
21        140       33
22        166       45
23        142       37
24        164       45
25       -162       39
26        156       39
27       -178       53
28       -178       29
29       -150       59
30       -178       35
31       -176       57
32        138       43
33        164       59
34       -152       37
35        152       39
36       -178       61
37        164       35
38        174       51
39       -176       29
40        154       41
41       -140       51
42        120       35
43       -178       53
44       -168       55
45       -172       65
46       -126       59
47       -178       53
48       -144       45
49       -178       37
50       -122       59
51       -178       27
52       -176       43
53        128       27
54       -130       33
55        134       37
56       -156       55
57       -176       41
58        148       47
59        146       37
60       -164       37
61        158       35
62        124       47
63        162       63
64       -178       47
65        144       37
66       -170       25
67        120       41
68       -164       41
69       -178       45
70        140       47
71        164       45
72       -164       39
73       -178       41
74        120       35
75       -150       41
76       -154       45
77        124       43
78        148       39
79       -162       43
80        152       35
81       -138       39
82        124       29
83       -168       51
84        146       49
85       -178       35
86       -152       49
87       -162       43
88        160       53
89        152       35
90        126       31
91       -156       47
92       -174       33
93        164       41
94        160       37
95       -154       25
96       -178       41
97        142       49
98       -178       35
99       -178       51
100       138       35
101      -120       41
102      -160       47
103       148       37
104       166       41
105      -148       37
106       146       37
107      -168       53
108      -178       37
109       132       29
110      -122       57

代码:

wrld2 = st_as_sf(map('world2', plot=F, fill=T))
ggplot() +
  geom_sf(data=wrld2, fill='lightgrey') +
  geom_point(data=sites, aes(x = longitude, y = latitude), size = 4, 
             shape = 22, fill = "darkblue") +
  coord_sf(xlim=c(-180,-120), ylim=c(25,65)) +
  geom_sf(data=wrld2, fill='lightgrey') +
  geom_point() +
  geom_point(data=sites, aes(x = longitude, y = latitude), size = 4, 
             shape = 21, fill = "darkred") +
  coord_sf(xlim=c(120,240), ylim=c(25,65)) +
  theme(panel.background = element_rect(fill = "aliceblue"))

只有日期变更线的西部部分用正确的点绘制(其他部分放在上面): enter image description here

问题在于蓝色数据点未绘制在其特定范围(-180、-120 和 25,65)内,因为两个坐标系/日期变更线在 +/- 180° 附近。我似乎无法弄清楚如何定义正确的 xlim 以便经度刻度在 x 轴上保持不变。有没有人知道缺少什么或需要重新定义什么?非常感谢。

0 个答案:

没有答案
相关问题