你愿意/能够转换到
sf
而不是
sp
?
sf plot函数比spplot快得多,尽管布局有点不同。
library(sf)
my.dat_sf <- st_as_sf(my.dat)
plot(my.dat_sf[rev(variable.names)], max.plot=10, breaks=c(seq(from = 100, to = 5000, by = 500),5000),
pal = distinctColorPalette(length(seq(from = 100, to = 5000, by = 500))),
main = "TEST", border=NA, key.pos=4)
此外,可以尝试使用
rmapshaper::ms_simplify()
对于空间*-对象或
sf::st_simplify()
对于simplefeatures,它允许您根据给定的
dTolerance
. 因此,使用简化的多边形绘制也会更快。
原始空间多边形:
format(object.size(my.dat_sf), units="Kb")
“25599.2 KB”
以及简化的简单功能:
dat_sf_simple <- st_transform(my.dat_sf, crs = 3035)
dat_sf_simple <- st_simplify(dat_sf_simple, dTolerance = 1000, preserveTopology = T)
dat_sf_simple <- st_transform(dat_sf_simple, crs = 4326)
format(object.size(dat_sf_simple), units="Kb")
“7864.2 Kb”
绘制简化的simplefeature,它在我的8GB RAM机器上大约需要1分钟。
plot(dat_sf_simple[rev(variable.names)], max.plot=10, breaks=c(seq(from = 100, to = 5000, by = 500),5000),
pal = distinctColorPalette(length(seq(from = 100, to = 5000, by = 500))),
main = "TEST", border=NA, key.pos=4)
你也可以试试
ggplot2
但是我很确定最有效的解决方案是SF图。
library(ggplot2)
library(dplyr)
library(tidyr)
dat_sf_simple_gg <- dat_sf_simple %>%
dplyr::select(rev(variable.names), geometry) %>%
gather(VAR, SID, -geometry)
ggplot() +
geom_sf(data = dat_sf_simple_gg, aes(fill=SID)) +
facet_wrap(~VAR, ncol = 2)