0

I'm trying to plot some dots on a map in R but only half of them show up. I suppose it might have something to do with the dateline.

My sample data:

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

The code:

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"))

Only the Western part of the dateline is plotted with the correct dots (others are put on top): enter image description here

The problem is that the blue data points are not plotted in their specific range (-180,-120 and 25,65) because of the two coordinate systems/dateline around +/- 180°. I can't seem to figure how to define the correct xlim so that the longitude ticks remain the same on the x-axis. Has anyone an idea what is missing or needs to be re-defined? Many thanks.

Tim
  • 13
  • 4
  • Can you edit the longitude in `sites` such that its range is [0, 360] instead o f[-180, 180]? Also, your sample code above repeats the same lines twice, which is probably not what you intended. – Z.Lin Jan 08 '21 at 07:44
  • Unfortunately I cannot edit the longitudes since they're the specific output I have been given. – Tim Jan 08 '21 at 14:11

0 Answers0