2017-03-09 122 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

是的,謝謝!這應該工作。有趣的解決方案。我需要研究可能創造一個新的幾何來推廣這項任務(並且它可以在更大的範圍內工作)。 –