使用voronoi在传单中创建的曲面_多边形创建具有点数据的choropleth贴图
我有一个棘手的问题 我正试图将一些数据可视化为一种“漂亮”的元数据浏览器。基本点数据的格式如下:使用voronoi在传单中创建的曲面_多边形创建具有点数据的choropleth贴图,r,polygon,rgdal,r-leaflet,R,Polygon,Rgdal,R Leaflet,我有一个棘手的问题 我正试图将一些数据可视化为一种“漂亮”的元数据浏览器。基本点数据的格式如下: > print(tempdata[1:5, ]) Station Lat_dec Long_dec Surface_T 1 247 50.33445 -2.240283 15.19 2 245 50.58483 -2.535217 14.11 3 239 50.16883 -2.509250 15.41 4 225 50.3284
> print(tempdata[1:5, ])
Station Lat_dec Long_dec Surface_T
1 247 50.33445 -2.240283 15.19
2 245 50.58483 -2.535217 14.11
3 239 50.16883 -2.509250 15.41
4 225 50.32848 -2.765967 15.34
5 229 50.63900 -2.964800 14.09
我可以使用Lat、Long和Temp创建以下voronoi多边形,并使用一个简单的框来剪裁它们,这样它们就不会永远延伸
# Creating Stations
stations <- st_as_sf(df,
coords = c("Long_dec","Lat_dec")
)
# Create voronoi/thiessen polygons
v <- stations %>%
st_union() %>%
st_voronoi() %>%
st_collection_extract()
# Creating boundary box
box <- st_bbox(stations) %>%
st_as_sfc()
# Clipping voronoi to boundary box
hmm <- st_crop(v, box)
绘制为:
leaflet() %>%
addPolygons(data = hmm) %>%
addProviderTiles(providers$Esri.WorldTerrain)
我想做的是,根据温度给表面多边形上色,例如,越热越红等等。我已经尝试了所有的方法,通常是R崩溃
我认为这与没有任何关于曲面多边形的信息有关,例如站点或链接到原始数据的多边形ID号
我被难住了,任何帮助都会很棒
套餐:
library(sf)
library(dplyr)
library(rgdal)
library(leaflet)
更新:
> tempdata[1:10, ]
Station Lat_dec Long_dec Surface_T
1 247 50.33445 -2.240283 15.19
2 245 50.58483 -2.535217 14.11
3 239 50.16883 -2.509250 15.41
4 225 50.32848 -2.765967 15.34
5 229 50.63900 -2.964800 14.09
6 227 50.33757 -3.303217 15.12
7 217 50.16657 -3.563817 15.13
8 207 49.66683 -3.556550 15.04
9 213 50.16512 -3.824667 14.97
10 219 49.83707 -3.815483 14.78
stations <- st_as_sf(tempdata,
coords = c("Long_dec","Lat_dec"))
test <- st_sample(stations,
size = as.numeric(count(tempdata))
)
join <- st_sf("temp" = stations$Surface_T, geometry = test)
这对我来说也是一个新的。以前从未和沃罗诺斯合作过。但问题确实是,您的stations数据帧失去了st_union的所有功能。 仅仅添加它似乎不可行,因为多边形的顺序与之前点的顺序不同。因此,空间连接可能是一个很好的解决方法 使用我自己的示例数据:
library(sf)
library(leaflet)
#will work with any polygon
samplepoints_sf <- st_sample(bw_polygon, size = 2000, type = "random", crs = st_crs(4326))[1:500]
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
#create an sf-object like your example
bw_sf <- st_sf("some_variable" = sample(1:50, 500, replace = TRUE), geometry = samplepoints_sf)
#create the voronoi diagram, "some_variable" gets lost.
v <- bw_sf %>%
st_union() %>%
st_voronoi() %>%
st_collection_extract()
#do a spatial join with the original bw_sf data frame to get the data back
v_poly <- st_cast(v) %>%
st_intersection(bw_polygon) %>%
st_sf() %>%
st_join(bw_sf, join = st_contains)
#create a palette (many ways to do this step)
colors <- colorFactor(
palette = c("green", "yellow", "red"),
domain = (v_poly$some_variable)
#create the leaflet
leaflet(v_poly) %>% addTiles() %>%
addPolygons(fillColor = colors(v_poly$some_variable),
fillOpacity = 0.7,
weight = 1,
popup = paste("<strong> some variable: </strong>",v_poly$some_variable))
所以,希望这对你有用
这对我来说也是一个新的。以前从未和沃罗诺斯合作过。但问题确实是,您的stations数据帧失去了st_union的所有功能。 仅仅添加它似乎不可行,因为多边形的顺序与之前点的顺序不同。因此,空间连接可能是一个很好的解决方法 使用我自己的示例数据:
library(sf)
library(leaflet)
#will work with any polygon
samplepoints_sf <- st_sample(bw_polygon, size = 2000, type = "random", crs = st_crs(4326))[1:500]
# although coordinates are longitude/latitude, st_intersects assumes that they are planar
#create an sf-object like your example
bw_sf <- st_sf("some_variable" = sample(1:50, 500, replace = TRUE), geometry = samplepoints_sf)
#create the voronoi diagram, "some_variable" gets lost.
v <- bw_sf %>%
st_union() %>%
st_voronoi() %>%
st_collection_extract()
#do a spatial join with the original bw_sf data frame to get the data back
v_poly <- st_cast(v) %>%
st_intersection(bw_polygon) %>%
st_sf() %>%
st_join(bw_sf, join = st_contains)
#create a palette (many ways to do this step)
colors <- colorFactor(
palette = c("green", "yellow", "red"),
domain = (v_poly$some_variable)
#create the leaflet
leaflet(v_poly) %>% addTiles() %>%
addPolygons(fillColor = colors(v_poly$some_variable),
fillOpacity = 0.7,
weight = 1,
popup = paste("<strong> some variable: </strong>",v_poly$some_variable))
所以,希望这对你有用
到目前为止,你是如何尝试给这些东西上色的,但没有效果呢?我只在传单中尝试过添加颜色,非常感谢你花时间纠正我的拼写错误。到目前为止,你是否尝试过给这些东西上色,但效果如何?我只在传单中尝试过添加颜色,非常感谢您抽出时间纠正我的拼写错误。我正在通过您的示例数据首先了解新函数的工作原理,但是我的环境中没有bw_多边形,这个变量是什么?它可以是任意多边形吗?非常感谢,它可以是任意多边形/边界框等,st_sample将对该形状内的点进行采样。您好,我正在尝试使其工作,但我正在努力,我对R还是相当陌生,所以请原谅我。我已经用我现在的位置和一些解释数据更新了这个问题。让我困惑的是如何从我的数据中获取采样点!但您不需要采样点。我只是在重新创建你的tempdata数据,以便我可以显示工作。处理数据时,可以跳过该部分:-我收集的染料哈哈!我一直在挣扎,并没有简单的功能几何列目前,但使用原始数据帧作为反对站!我首先通过您的示例数据来了解新函数是如何工作的,但是我在环境中没有bw_多边形,这个变量是什么?它可以是任意多边形吗?非常感谢,它可以是任意多边形/边界框等,st_sample将对该形状内的点进行采样。您好,我正在尝试使其工作,但我正在努力,我对R还是相当陌生,所以请原谅我。我已经用我现在的位置和一些解释数据更新了这个问题。让我困惑的是如何从我的数据中获取采样点!但您不需要采样点。我只是在重新创建你的tempdata数据,以便我可以显示工作。处理数据时,可以跳过该部分:-我收集的染料哈哈!我一直在挣扎,并没有简单的功能几何列目前,但使用原始数据帧作为反对站!