我正在使用ggplot2从包含大约500k行的表中制作图形。
在我的ubuntu 20.04笔记本电脑(CPU i5 8265U)上,大约需要15秒,并且可以在Rstudio的绘图选项卡中正确显示。现在我刚获得一台PC并获得了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
再次不幸的是,最接近的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
在Ubuntu上:
> t2 - t1
Time difference of 10.26094 secs
在win10上:
> t2 - t1
Time difference of 23.292 secs
因此,主要问题是,一个系统如何在10秒内绘制图形,而另一个系统又在10分钟以上?即使使用基本图形优先系统,速度也快2倍?
仅仅是Ubuntu vs 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句