ggplot2中正交投影的2d密度图

时间:2018-01-30 15:28:56

标签: r ggplot2

在正投影中绘制2d密度估计时,我得到了人工制品。问题是轮廓线不会在日期线处缠绕。这可以在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))

ggplot2 artifact in 2d density plot with orthographic projection

1 个答案:

答案 0 :(得分:2)

不确定它是否正是您所寻找的:

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