0

我是 R 新手。我有一组纬度、经度坐标,并且我已经生成了一张带有这些点的地图。 在此处输入图像描述

编辑:这是点的数据,

lat <- c(44.3672, 39.3421, 33.978, 36.3901, 32.8388, 38.7519, +
         37.1863, 28.2408, 41.7098, 30.4127)
lon <- c(-83.5215, -86.0034, -84.579, -83.8163, -83.6077, -85.4381,+
         -85.2338, -82.7283, -85.0308, -88.4076)
df <- data.frame(lon, lat)

这是我用来绘制点的代码,(从这篇文章中获得)

library(maps)
library(ggplot2)
us_states<-map_data('state')
p <- ggplot(legend=FALSE) +
  geom_polygon( data=us_states, aes(x=long, y=lat,group=group)) +
  theme(panel.background = theme_blank()) +
  theme(panel.grid.major = theme_blank()) +
  theme(panel.grid.minor = theme_blank()) +
  theme(axis.text.x = theme_blank(),axis.text.y = theme_blank()) +
  theme(axis.ticks = theme_blank()) +
  xlab("") + ylab("")
# add a single point
p <- p + geom_point(data=df,aes(lon,lat),colour="blue",size=3)
p

现在我想获取每个点,计算一个以该点为中心的 20 公里乘 20 公里的单元格,然后在地图上绘制生成的单元格。然后如何使用这样的单元格大小在地图上构建网格?谢谢。

4

1 回答 1

1
poly.df <- as.data.frame( t( apply(df, 1, 
              function(x) c(                        # for longitude, 
               xmin=x[1]-cos(x[2]*2*pi/360)*20/111.2,  # km/degr varies
               xmax=x[1]+cos(x[2]*2*pi/360)*20/111.2,  # with latitude
               ymin=x[2]-20/111.2,            # but not for lattitude
               ymax=x[2]+20/111.2) ) ) )

坦率地说,我不确定这是一个简单的 cos(纬度)调整。我检查了维基百科中的表格,它非常接近:

 round( cos(seq(90, 0, by=-15)*2*pi/360)*111.2 , 1)
[1]   0.0  28.8  55.6  78.6  96.3 107.4 111.2

但这确实得到看起来大致准确的矩形。我认为任何偏心都来自点的位置。

p+geom_rect(data=poly.df, color="red", fill="transparent", 
       aes(xmin=xmin.lon,xmax=xmax.lon, ymin=ymin.lat,ymax=ymax.lat) )

构建网格:

    p+geom_vline(xintercept= seq(-50, -130, by=-1), color="red")+
      geom_hline(yintercept= seq(25,50, by=1), color="red")
于 2013-10-20T19:43:40.057 回答