围绕空间数据点创建等值线

Creat isoline around spatial data points

我有以下问题。我想在代表机场的欧洲空间点周围创建等值线。在所有数据点周围,我想创建代表航班排放的等值线。所有航班出发地为苏黎世,到达地为欧洲各地。

df <- data.frame(flight_number = c(1,2,3,4,5,6,7), 
                 dep_lon = c(8.548056,8.548056,8.548056,8.548056,8.548056,8.548056,8.548056),
                 dep_lat = c(47.45806,47.45806,47.45806,47.45806,47.45806,47.45806,47.45806),
                 arr_lon = c(11.548056,16.569700,13.548056, 27.825100, 16.569700,11.569700,19.569700),
                 arr_lat = c(47.45806,48.11030,47.45806,43.23210,48.11030,44.45806,49.45806), 
                 EMISSIONS_KGCO2EQ = c(100,200,300,400,1000,400,200))

ggplot()+
  geom_point(data = df, aes(x = dep_lon, y = dep_lat), col = "red")+
  geom_point(data = df, aes(x = arr_lon, y = arr_lat), col = "blue")+
  geom_contour(data = df, aes(x = arr_lon, y = arr_lat, z= EMISSIONS_KGCO2EQ))

我用这段代码绘制了苏黎世出发点和到达点。我想要每个航班的“EMISSIONS_KGCO2EQ”等值线。但是我得到的是以下错误消息:

Warning messages:
1: stat_contour(): Zero contours were generated 
2: In min(x) : no non-missing arguments to min; returning Inf
3: In max(x) : no non-missing arguments to max; returning -Inf

我没有收到错误消息,因为没有。 Inf 值或计算除以 0。

我想要的是等值线,其中苏黎世的排放量为 0,并且根据每个航班的值增长,每个排放值都有一个等值线。

感谢您的帮助。

如果您查看 geom_contour 的文档,则说明 x 和 y 值应为规则网格。所以你需要插入一个规则的网格并将其用于你的轮廓。这是一种方法...

library(tidyverse)
library(interp)

interpolated <- interp(df$arr_lon, df$arr_lat, df$EMISSIONS_KGCO2EQ, 
                       duplicate = "mean",    #you have duplicated values
                       output = "grid")

#convert this to a long form dataframe
interp_df <- expand_grid(i = seq_along(interpolated$x), 
                         j = seq_along(interpolated$y)) %>% 
  mutate(lon = interpolated$x[i],
         lat = interpolated$y[j],
         emissions = map2_dbl(i, j, ~interpolated$z[.x,.y])) %>% 
  select(-i, -j)

#then you can use this in your plot
ggplot()+
  geom_point(data = df, aes(x = dep_lon, y = dep_lat), col = "red") +
  geom_point(data = df, aes(x = arr_lon, y = arr_lat), col = "blue") +
  geom_contour(data = interp_df, aes(x = lon, y = lat, z = emissions)) 

这个小数据集看起来仍然不太好,但希望您的实际数据中有更多!您还需要决定如何处理重复项。