2017-02-02 2 views
0

ゾーン外にある小さなセグメント(data = station_EVHOE)を削除したいと思います。 the map here私が描いたセグメントの座標

このために、該当するゾーン(右側の領域)を区切る黒い線分を描きました。 左のゾーンにあるポイントを削除したいと思います。

マイコードはggplotで作られている。

d <- ggplot() + 
    coord_map(xlim = c(-12,-1), ylim = c(43,52)) + 
    geom_polygon(aes(x=longitude, y=latitude), data = coast_EVHOE) + 
    geom_segment(aes(x = longitude_début, y = latitude_début, xend = longitude_fin, yend = latitude_fin, colour = as.factor(annee)), data = station_EVHOE) + 
    geom_segment(aes(x = -4.374794, y = 47.7975, xend = -7.8694, yend = 43.773630)) 

だから、それが右の領域外の点を除去するために、黒のセグメントの座標を抽出することができますか?ここで

+1

確かに、しかし、あなたはggplot2の外にそれをしなければなりません。 'rgeos'と' sp :: over'を参照してください。例えば。 http://stackoverflow.com/questions/19002744/spover-for-point-in-polygon-analysis –

答えて

1

この考え方に基づいて:https://math.stackexchange.com/questions/274712/calculate-on-which-side-of-a-straight-line-is-a-given-point-located

#determine which station are on the right side of the line 
#I use only one point, you can adapt to check if the two point of the station are on the right side of the plot 

station_EVHOE$right_side = 
    ((station_EVHOE$longitude_début + 4.374794)*(43.773630 - 47.7975)) - 
    ((station_EVHOE$latitude_début - 47.7975)*(-7.8694 + 4.374794)) < 0 

d <- ggplot() + 
    coord_map(xlim = c(-12,-1), ylim = c(43,52)) + 
    geom_polygon(aes(x=longitude, y=latitude), data = coast_EVHOE) + 

# plot only the station at the right side of the line 
    geom_segment(aes(x = longitude_début, y = latitude_début, xend = longitude_fin, yend = latitude_fin, colour = as.factor(annee)), data = station_EVHOE[station_EVHOE$right_side,]) + 
    geom_segment(aes(x = -4.374794, y = 47.7975, xend = -7.8694, yend = 43.773630)) 
+0

それは動作します!オペレーションの "+"を " - "に変更しなければなりませんでした "(station_EVHOE $latitude_début+ 47.7975)"。本当にありがとうございました! – Loulou

+0

あなたはそうだ、私はそれを更新する.. – timat

関連する問題