我有一个大的空间数据集(12M行).几何图形是地图上的点.对于数据集中的每一行,我想找到距离该点500米范围内的所有点.
在r中,使用sf,我一直试图通过并行循环遍历每一行并运行st_buffer和st_intersects来做到这一点,然后将结果保存为键值格式的列表(键是原点,值是邻居).
问题是数据集太大.即使并行化到超过60个核心,操作也需要很长时间(> 1周且通常会崩溃).
这种蛮力方法有哪些替代方案?是否可以使用sf构建索引?也许将操作推送到外部数据库?
Reprex:
library(sf)
library(tidyverse)
library(parallel)
library(foreach)
# example data, convert to decimal:
nc <- st_read(system.file("shape/nc.shp", package="sf")) %>% st_transform(32618)
# expand the data a a bit to make the example more interesting:
nc <- rbind(nc,nc,nc)
nc <- nc %>% mutate(Id = row_number())
## can run in parallel if desired:
# num_cores <- parallel::detectCores()-2
# cl <- makeSOCKcluster(num_cores)
# registerDoSNOW(cl)
# or just run in sequence:
registerDoSEQ()
neighbors <- foreach(ii = 1:nrow(nc)
, .verbose = FALSE
, .errorhandling …Run Code Online (Sandbox Code Playgroud) 如何在R的传单包中自定义addMarkers函数的着色?
群集的默认着色是:
我想将范围和颜色更改为:
JS Leaflet具有以下功能:https: //github.com/Leaflet/Leaflet.markercluster#customising-the-clustered-markers
这是否可以通过R包中的markerClusterOptions参数实现?
leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions()
)
Run Code Online (Sandbox Code Playgroud) 我想在几个ggplot对象的中心放置一个注释.
我研究过并发现了一些类似的问题,例如:ggplot2中geom_text的相对定位?
到目前为止,我发现的唯一答案是操纵绝对范围(例如",y = ymax/2").
我想在打印到.pdf之前在循环中添加注释图层.我可以使用+/- Inf将注释放在角落中,如下所示:
plot.list<-list()
g<- qplot(1,1)
plot.list[[length(plot.list)+1]]<-g
plot.list[[length(plot.list)+1]]<-g
pdf("MyReport.pdf"
,width = 14
,height=8.5
,paper="a4r")
for(i in 1:length(plot.list)){
print(plot.list[[i]]+
annotate("text",x=Inf,y=Inf,hjust=1,vjust=1
,label="PLEASE DO NOT DISTRIBUTE"
,fontface="bold",color="darkred",alpha=0.3))
}
dev.off()
Run Code Online (Sandbox Code Playgroud)
如何将注释放在中心而不是角落?
如何更改从 Leaflet for R 界面中定义集群对象的默认 CSS 类?例如,如果我想从 .marker-cluster-small 类中删除不透明度,我该如何在 R 中执行此操作?
这是创建集群类的 CSS:https : //github.com/Leaflet/Leaflet.markercluster/blob/64a2d5711521e56cac8ab863fb658beda5690600/dist/leaflet.markercluster-src.js
例如,我想从集群中删除不透明度,例如
.marker-cluster-small {
background-color: rgba(181, 226, 140, 1.0);
}
.marker-cluster-small div {
background-color: rgba(110, 204, 57, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法从 iconCreateFunction 中做到这一点?
library(leaflet)
leaflet(quakes) %>% addTiles() %>% addMarkers(
clusterOptions = markerClusterOptions(iconCreateFunction=JS("function (cluster) {
var childCount = cluster.getChildCount();
var c = ' marker-cluster-';
if (childCount < 100) {
c += 'large';
} else if (childCount < 1000) {
c += 'medium';
} else {
c += …Run Code Online (Sandbox Code Playgroud) 我想使用ggplot2用共同的y轴并排绘制2个不同的图表:
p1)使用geom_rect()的“区域矩形”图
p2)使用geom_density()的密度图
我已经通过使用grid.arrange()接近了,但是y轴并不完全对齐。我认为facet_wrap或facet_grid在这里不起作用,但我可能错了。
rm(list=ls())
library(ggplot2)
library(gridExtra)
library(dplyr)
df<-structure(list(total_ulr = c(0.442, 0.679, 0.74, 0.773, 0.777,
0.8036, 0.87, 0.871, 0.895, 0.986, 1.003, 1.2054, 1.546, 1.6072
), width = c(4222L, 14335L, 2572L, 2460L, 1568L, 8143L, 3250L,
17119L, 3740L, 3060L, 2738L, 1L, 1L, 790L), w = c(4222L, 18557L,
21129L, 23589L, 25157L, 33300L, 36550L, 53669L, 57409L, 60469L,
63207L, 63208L, 63209L, 63999L), wm = c(0L, 4222L, 18557L, 21129L,
23589L, 25157L, 33300L, 36550L, 53669L, 57409L, 60469L, 63207L,
63208L, 63209L), wt = c(2111, 11389.5, 19843, 22359, 24373, …Run Code Online (Sandbox Code Playgroud)