【问题标题】:Coordinates of a segment that I have drawn我绘制的段的坐标
【发布时间】:2017-06-19 13:33:23
【问题描述】:

我想删除区域外的小段(数据 = 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))

那么,是否可以提取黑色部分的坐标,以去除右侧区域之外的点?

【问题讨论】:

标签: r ggplot2 coordinates extraction segment


【解决方案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))

【讨论】:

  • 有效!我只需要在操作“(station_EVHOE$latitude_début + 47.7975)”中将符号“+”更改为“-”。非常感谢提马特!
猜你喜欢
  • 1970-01-01
  • 2021-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-17
  • 2013-01-05
  • 2020-06-28
  • 1970-01-01
相关资源
最近更新 更多