{"word_count": 540, "character_count": 3915}
I am still working with @3wen on visualizations of the North Pole. So far, it was not that difficult to generate maps, but we started to have problems with the ice region in the Arctic. More precisely, it was complicated to compute the area of this region (even if we can easily get a shapefile). Consider the globe,worldmap &#60;- ggplot() + geom_polygon(data = world.df, aes(x = long, y = lat, group = group)) +scale_y_continuous(breaks = (-2:2) * 30) +scale_x_continuous(breaks = (-4:4) * 45)and then, add three points in the northern hemisphere, and plot the associated triangleP1 &#60;- worldmap + geom_polygon(data = triangle, aes(x = long, y = lat, group = group), fill ="blue", alpha = 0.6, col = "light blue", size = .8)+geom_point(data = triangle, aes(x = long, y = lat, group = group),colour = "red")+for some given projection, e.g.coord_map("ortho", orientation=c(61, -74, 0))This can be done with the following functionproj1=function(x=75){triangle &#60;- data.frame(long=c(-70,-110,-90*(x&#60;90)+90*(x&#62;90)),lat=c(60,60,x*(x&#60;90)+(90-(x-90))*(x&#62;90)),group=1, region=1)worldmap &#60;- ggplot() + geom_polygon(data = world.df, aes(x = long, y = lat, group = group)) +scale_y_continuous(breaks = (-2:2) * 30) +scale_x_continuous(breaks = (-4:4) * 45)P1 &#60;- worldmap + geom_polygon(data = triangle, aes(x = long, y = lat, group = group), fill ="blue", alpha = 0.6, col = "light blue", size = .8)+geom_point(data = triangle, aes(x = long, y = lat, group = group),colour = "red")+coord_map("ortho", orientation=c(61, -74, 0)) print(P1)} or I am not sure if I understand why the projection of the triangle is not convex on the graph above, but say it's not a big deal, here. Actually, our problem is that our interest is on regions (polygons, from a geometrical point of view) that do contain the North Pole. And here, it starts to be messy. I can easily move the upper point on the other side of the globe, but the polygon is not correct, I do understand that it should be a problem, non-trivial, but it means that it should not be that simple to compute the area of a polygon (a region) that contains the North Pole. Which is exactly what we did observe in our computation. And I believe that one heuristic interpretation is related to the following graphMy skills in geometry are extremely poor. So do not expect that I will go through the code of the function that compute the area of a polygon ! Actually, my idea is the following : if the problem is that the North Pole is in the region, let's consider some rotation, to shift the North Pole on the Equation. The code here is, from latitudes and longitude, to get new latitudes and longitudes, after a rotation around the y-axis (the North Pole will go down, along Greenwhich meridian) isrotation=function(Z,theta){lon=Z[,1]/180*pi; lat=Z[,2]/180*pix=cos(lon)*cos(lat)y=sin(lon)*cos(lat)z=sin(lat)pt1=cbind(x,y,z)M=matrix(c(cos(theta),0,-sin(theta),0,1,0,sin(theta),0,cos(theta)),3,3)pt2=t(M%*%t(pt1))lat=asin(pt2[,3])*180/pilon=atan2(pt2[,2],pt2[,1])*180/pireturn(cbind(lon,lat))}With a rotation from  (no change) to  (the North Pole on the equator), we getFrom now on, it is possible to compute the area of any region containing the North Pole ! One should simply apply the rotation function on all datebases generated from shapefiles (and then the opposite rotation to get a proper location) ! We can then compute the centroid of the ice region, for example,r.glace=glacer.glace[,1:2]=rotation(glace[,1:2],pi/2)M=matrix(NA,length(unique(glace$id)),3)j=0for(i in unique(glace$id)){j=j+1Polyglace &#60;- as(r.glace[glace$id==i,c("long","lat")],"gpc.poly")M[j,1]=area.poly(Polyglace)M[j,2:3]=centroid(r.glace[r.glace$id==i,c("long","lat")])}Z=c(weighted.mean(M[,2],M[,1]),weighted.mean(M[,3],M[,1]))rotation(rbind(Z),-pi/2)[1,])And we getand below, we can visualize all the locations of the centroid of the ice region in the past 25 years