Reputation: 9027
I get artifacts when plotting 2d density estimates in an orthographic projection. The problem is that the contour lines don't wrap around at the date line. Can this be done in ggplot2?
library(tidyverse)
# points on a map, longitude between -180 and 180
df = data_frame(lon=c(rnorm(100, -180, 50),
rnorm(100, 180, 50)),
lat=rnorm(200, 60, 10)) %>%
filter(lon > -180, lon < 180)
# 2d density, orthographic projection
ggplot(data=df) +
coord_map('ortho') +
geom_point(aes(x=lon, y=lat)) +
stat_density2d(aes(x=lon, y=lat))
Upvotes: 2
Views: 239
Reputation: 1076
Not sure that it is exactly what you are looking for :
m <- mapproject(df$lon, df$lat, projection="orthographic", parameters=NULL,
orientation=NULL)
ggplot(data=as.data.frame(cbind(m$x, m$y))) +
geom_point(aes(x=V1, y=V2)) +
geom_density2d(aes(x=V1, y=V2))
Upvotes: 2