R levelplot,非连续的纬度和经度值

发布于 2024-12-01 20:44:25 字数 855 浏览 1 评论 0原文

我有表示为纬度-经度的数据集和与每个纬度-经度对关联的值(名为“类”),我想将其表示为在“R”的“lattice”包下使用levelplot()或contourplot() ”。 示例数据集如下所示:

> data_2[510:520,]
          lon      lat class
510 -47.61849 40.00805     2
511 -47.36740 40.01180     1
512 -47.11629 40.01551     1
513 -46.86518 40.01918     1
514 -46.61404 40.02282     1
515 -46.36290 40.02642     3
516 -46.11173 40.02999     1
517 -45.86056 40.03352     1
518 -45.60937 40.03700     3
519 -45.35817 40.04045     3
520 -45.10695 40.04386     3

主数据集中的经度和纬度值不连续。

我的问题是我没有所有纬度-经度组合的“类”值,因此,当我尝试绘制上述值时,留下了很多空白空间。我想要的是获得一个连续的、填充的(对于所有经纬度组合)图。

以下是我尝试绘制的方法之一的示例:

levelplot(data_2$class ~ data_2$lon * data_2$lat,data = data_2,region = TRUE,aspect =“fill”)

levelplot() 或contourplot() 函数中是否有可用的选项可以用来实现此目的或者“R”中是否有其他包/方法可以帮助我提出这个解决方案?

I have data-set represented as latitude-longitude and a VALUE(named "class") associated with each latitude-longitude pair, which i want to represent as using levelplot() or contourplot() under the "lattice" package for "R".
sample dataset looks like this:

> data_2[510:520,]
          lon      lat class
510 -47.61849 40.00805     2
511 -47.36740 40.01180     1
512 -47.11629 40.01551     1
513 -46.86518 40.01918     1
514 -46.61404 40.02282     1
515 -46.36290 40.02642     3
516 -46.11173 40.02999     1
517 -45.86056 40.03352     1
518 -45.60937 40.03700     3
519 -45.35817 40.04045     3
520 -45.10695 40.04386     3

The longitude and latitude values in the main dataset are not continuous.

My problem is I do not have "class" value for all the latitude-longitude combinations, and due to this there are lot of empty spaces left when i am trying to plot the above values. What I want is to get a continuous, filled (for all lat-long combinations) plot.

The following is an example of one of the ways i am trying to plot:

levelplot(data_2$class ~ data_2$lon * data_2$lat, data = data_2, region = TRUE, aspect = "fill")

Are there any options available in the levelplot() or contourplot() functions which i can use to achieve this or is there any other package/method in "R" which could help me come up with this solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

2024-12-08 20:44:25

我建议您查看免费电子书“地统计绘图实用指南”(http://spatial-analyst.net/book/download),以回顾空间估计方法,其中包含大量 R 示例。

正如 Ben 指出的,您需要进行某种空间插值。以下是使用 intamap 包中的 interpolate 函数的快速示例:

library(intamap)
library(lattice)

# Generate an example dataset
set.seed(10)

class1 <- data.frame(lon=rnorm(50, mean=-46, sd=4), 
                     lat=rnorm(50, mean=32, sd=4), 
                     value=1)

class2 <- data.frame(lon=rnorm(50, mean=-40, sd=4), 
                     lat=rnorm(50, mean=39, sd=4), 
                     value=2)

class3 <- data.frame(lon=rnorm(50, mean=-50, sd=3), 
                     lat=rnorm(50, mean=40, sd=2), 
                     value=3)

df <- rbind(class1, class2, class3)

# Generate a 50 x 50 grid over which to predict new values
prediction.grid <- expand.grid(lon=seq(from=min(df$lon), 
                                       to=max(df$lon), 
                                       length=50),
                               lat=seq(from=min(df$lat), 
                                       to=max(df$lat), 
                                       length=50))
# Spatialize the data.frames                           
coordinates(df) <- c("lon", "lat")
gridded(prediction.grid) <- c("lon", "lat")

fit <- interpolate(df, prediction.grid)

# Built-in plots, including variogram and pertinent stats:
plot(fit)

# Pull out the fitted values into a dataframe
predictions <- as.data.frame(t(fit$outputTable))

levelplot(mean ~ x * y, data=predictions, region=TRUE, aspect="fill")

I recommend taking a look at the free ebook "A Practical Guide to Geostatistical Mapping" (http://spatial-analyst.net/book/download) for a review of spatial estimation methods with plenty of examples in R.

As Ben pointed out, you'll need to do some sort of spatial interpolation. Here's a quick example using the interpolate function in the intamap package:

library(intamap)
library(lattice)

# Generate an example dataset
set.seed(10)

class1 <- data.frame(lon=rnorm(50, mean=-46, sd=4), 
                     lat=rnorm(50, mean=32, sd=4), 
                     value=1)

class2 <- data.frame(lon=rnorm(50, mean=-40, sd=4), 
                     lat=rnorm(50, mean=39, sd=4), 
                     value=2)

class3 <- data.frame(lon=rnorm(50, mean=-50, sd=3), 
                     lat=rnorm(50, mean=40, sd=2), 
                     value=3)

df <- rbind(class1, class2, class3)

# Generate a 50 x 50 grid over which to predict new values
prediction.grid <- expand.grid(lon=seq(from=min(df$lon), 
                                       to=max(df$lon), 
                                       length=50),
                               lat=seq(from=min(df$lat), 
                                       to=max(df$lat), 
                                       length=50))
# Spatialize the data.frames                           
coordinates(df) <- c("lon", "lat")
gridded(prediction.grid) <- c("lon", "lat")

fit <- interpolate(df, prediction.grid)

# Built-in plots, including variogram and pertinent stats:
plot(fit)

# Pull out the fitted values into a dataframe
predictions <- as.data.frame(t(fit$outputTable))

levelplot(mean ~ x * y, data=predictions, region=TRUE, aspect="fill")
我乃一代侩神 2024-12-08 20:44:25

您需要首先进行某种插值。 akima 包可能是您最好的选择,请参阅 ?akima 中的示例。 gstat::krige 是另一种可能性。

You need to do some kind of interpolation first. The akima package is probably your best bet, see the examples in ?akima. gstat::krige is another possibility.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文