Gae*_*elS 3 windows ubuntu r ggplot2
我正在使用 ggplot2 从包含大约 500k 行的表中制作一个图表。
在我的 ubuntu 20.04 笔记本电脑(CPU i5 8265U)上,大约需要 15 秒,并在 Rstudio 的绘图选项卡中正确显示。现在我刚买了一台装有 win 10 的电脑,一个更好的 CPU (i5 10400F) 和一个 GPU (GTX 1660 Super)。同一张图需要永远构建。如果我等待足够长的时间,代码会运行超过 10 分钟,但仍然不会显示在绘图选项卡中。
对我来说不幸的是,我无法共享数据,因此无法制作代表,该图的代码是:
> t1 <- Sys.time()
> gr_dbh_h <- tree16_temp %>%
+ filter(lu_en_simple2 %in% c("Evergreen Forest", "Deciduous Forest")) %>%
+ select(dbh, h, live_dead, lu_en_simple2_f) %>%
+ ggplot() +
+ geom_point(aes(x = dbh, y = h, color = live_dead), alpha = 0.5, shape = 3) +
+ labs(color = "", x = "Diameter at breast height (cm)", y = "Tree total height (m)") +
+ facet_wrap(~lu_en_simple2_f)
> t2 <- Sys.time()
> t2 - t1
Time difference of 0.1159708 secs
> gr_dbh_h
> t3 <- Sys.time()
> t3 - t2
Time difference of 9.901076 mins
Run Code Online (Sandbox Code Playgroud)
不幸的是,最接近的 reprex 没有同样的问题,只是在 ubuntu 笔记本电脑上显示的渲染速度比 win10 PC 快 2 倍(而不是我的主代码中的 60 倍):
library(tidyverse)
tt <- tibble(
x = rnorm(500000),
y = rnorm(500000),
cat = rep(c("aa", "bb", "cc", "dd", "ee"), 100000),
group = c(rep("A", 200000), rep("B", 300000))
)
t1 <- Sys.time()
ggplot(tt) +
geom_point(aes(x, y, color = group), alpha = 0.5) +
facet_wrap(~cat)
t2 <- Sys.time()
t2 - t1
Run Code Online (Sandbox Code Playgroud)
在Ubuntu上:
> t2 - t1
Time difference of 10.26094 secs
Run Code Online (Sandbox Code Playgroud)
在win10上:
> t2 - t1
Time difference of 23.292 secs
Run Code Online (Sandbox Code Playgroud)
所以主要问题是一个系统如何在 10 秒内绘制图表而另一个系统在 10 分钟以上绘制图表?即使使用基本的图优先系统也快 2 倍?
仅仅是 Ubuntu 与 Windows 的比较吗?GPU 会扰乱渲染吗?
Rstudio 和 R 是相同版本,在撰写本文时软件包都是最新的。
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_Europe.1252 LC_CTYPE=English_Europe.1252 LC_MONETARY=English_Europe.1252
[4] LC_NUMERIC=C LC_TIME=English_Europe.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggthemr_1.1.0 devtools_2.3.1 usethis_1.6.1 webshot_0.5.2 tmap_3.1 bookdown_0.20 knitr_1.29
[8] sf_0.9-5 BIOMASS_2.1.3 scales_1.1.1 ggrepel_0.8.2 ggpubr_0.4.0 lubridate_1.7.9 forcats_0.5.0
[15] stringr_1.4.0 dplyr_1.0.2 purrr_0.3.4 readr_1.3.1 tidyr_1.1.2 tibble_3.0.3 ggplot2_3.3.2
[22] tidyverse_1.3.0
Run Code Online (Sandbox Code Playgroud)
欢迎使用蹩脚的图形设备。在 OS X 上,有时保存为 pdf 然后在预览中打开 pdf 比将图形渲染到 RStudio 窗口更快。另外,下面是一个示例,文本渲染在一种图形设备中花费的时间比在另一种图形设备中长约 300 倍。
我建议安装 RStudio daily build,安装ragg包,然后在图形设置中将后端设置为 agg:
这应该会给你带来不错的性能渲染。它还将解决默认 Windows 图形设备存在的一些其他问题,因此无论如何它都是一个不错的选择。
| 归档时间: |
|
| 查看次数: |
2569 次 |
| 最近记录: |