Jak*_*e L 3 graphics r spatial rgeo r-sf
我最近买了一台新的 MacBook Pro,但遇到了一些与 R 图形相关的问题。在绘制 sf 对象时,R 的运行速度非常慢。我发现这个问题已有几年历史了(此处: https: //github.com/rstudio/rstudio/issues/3866),但从未提出任何解决方案。作为参考,RStudioGD绘制对象的速度比它慢 300 倍以上pdf,这让我抓狂。从上面的链接分享可重现的示例(尽管系统时间数字是我的):
<<================= 从上面的链接复制:========================== =>>
我想绘制此处找到的缅甸形状文件:
https://gadm.org/download_country_v3.html
library(rgdal)
library(sp)
tdir = tempdir()
get_poly = function() {
tmp = tempfile(tmpdir = tdir)
download.file(
'https://biogeo.ucdavis.edu/data/gadm3.6/shp/gadm36_MMR_shp.zip',
tmp
)
unzip(tmp, exdir = tdir)
readOGR(tdir, 'gadm36_MMR_0', stringsAsFactors = FALSE)
}
Run Code Online (Sandbox Code Playgroud)
使用 RStudioGD 绘制此图比绘制 pdf 慢得多:
mmr = get_poly()
system.time(plot(mmr))
# user system elapsed
# 128.162 0.510 129.271
unlink(tdir, recursive = TRUE)
Run Code Online (Sandbox Code Playgroud)
重新启动 R 以清除缓存/开销并再次运行:
mmr = get_poly()
tpdf = tempfile(tmpdir = tdir, fileext = 'pdf')
system.time({
pdf(tpdf)
plot(mmr)
dev.off()
})
# user system elapsed
# 0.423 0.027 0.460
unlink(tdir, recursive = TRUE)
Run Code Online (Sandbox Code Playgroud)
因此,使用外部设备的速度大约快 300 倍...知道吗?
png 也需要 < 1 秒
<<====================来自链接的结束副本======================>>
我使用的是 macOS Big Sur 11.1 RStudio 版本 1.3.1093
(我遇到了一些其他与图形相关的模糊问题,我在这里发布了:quartz device behaving odds after mac update - R mac,但我不确定这两者是否相关)。
小智 5
我也有同样的问题。切换到图形设备后端后已修复:“AGG”。
> system.time(plot(mmr))
user system elapsed
0.213 0.019 0.243
Run Code Online (Sandbox Code Playgroud)
我的会话信息:
R version 4.1.1 (2021-08-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.6
RStudio 2021.09.0+351 "Ghost Orchid" Release (077589bcad3467ae79f318afe8641a1899a51606, 2021-09-20) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 11_6_0) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36
Run Code Online (Sandbox Code Playgroud)