2017-03-09 68 views
0

我正在绘制一个甚高频接收器位置的地图。对于每个接收机位置,我想添加连接到每个接收机的天线的估计检测距离(视距为12km)。geg_segment替代ggplot中绘制点范围

我已经能够做到这一点使用geom_segment如下所示:

enter image description here 但我想更精确地表示该天线检测与气球代替线段范围(下面例子PIC)

Map of Receiver Locations with desired detection ranges

这里是我当前的代码重现线段的方法:

library(ggmap);library(ggplot2) 

    tower <- data.frame(id="somewhere", lat = 29.5634, lon = -82.6111) 

    map1 <- get_map(location = tower[,c("lon","lat")], maptype = "satellite", zoom=9) 

    tower$start = tower$lon - 0.2 # creates segment length of approx 12km in degrees 
    tower$end = tower$lon + 0.2 # creates segment length of approx 

    ggmap(map1) + geom_segment(data=tower, aes(x=tower$start, 
          y=tower$lat, 
          xend=tower$end, 
          yend=tower$lat), 
          size=1, colour="red") + 
        geom_point(data=tower, aes(x=lon, y=lat), colour="black") 

有关如何重新创建示例图的任何建议,将不胜感激。

感谢 科比

回答

1

这是一个有点冗长,但我们可以添加四个geom_curve创建形状。

注意coord_cartesian()最后,geom_curve is not implemented for non-linear coordinates所以我们强迫坐标是笛卡儿。这意味着这种方法只适用于小规模。

ggmap(map1) + 
    # geom_segment(data = tower, 
    #    aes(x = start, 
    #     y = lat, 
    #     xend = end, 
    #     yend = lat), 
    #    size = 1, colour = "red") + 
    geom_curve(data = tower, 
      aes(x = lon, 
       y = lat, 
       xend = I(lon - .2), 
      curvature = -.5, 
      angle = 45,color = 'yellow') + 
    geom_curve(data = tower, 
      aes(x = lon, 
       y = lat, 
       xend = end, 
       yend = lat), 
      curvature = .5, 
      angle = 135,color = 'yellow') + 
    geom_curve(data = tower, 
      aes(x = lon, 
       y = lat, 
       xend = start, 
       yend = lat), 
      curvature = .5, 
      angle = 135,color = 'yellow') + 
    geom_curve(data = tower, 
      aes(x = lon, 
       y = lat, 
       xend = end, 
       yend = lat), 
      curvature = -.5, 
      angle = 45,color = 'yellow') + 
    geom_point(data = tower, aes(x = lon, y = lat), colour = "black") + 
    coord_cartesian() 

enter image description here

我想或者新geom_*可以创建。

+0

它解决了你的问题吗? – GGamba

+0

是的,谢谢!这应该工作。有趣的解决方案。我需要研究可能创造一个新的几何来推广这项任务(并且它可以在更大的范围内工作)。 –