ggplot2/Rstudio图形渲染速度慢-GPU问题?

ggplot2/Rstudio图形渲染速度慢-GPU问题?,r,windows,ubuntu,ggplot2,R,Windows,Ubuntu,Ggplot2,我正在使用ggplot2从包含大约500k行的表中创建一个图表 在我的Ubuntu20.04笔记本电脑(CPU i5 8265U)上,它大约需要15秒,并在Rstudio的绘图选项卡中正确显示。现在我刚买了一台装有win 10的PC,一台更好的CPU(i5 10400F)和一个GPU(GTX 1660 Super)。同样的图表需要永远建立。如果我等待的时间足够长,我会让代码在10分钟内运行,但仍不会显示在绘图选项卡中 不幸的是,我无法共享数据,因此无法制作reprex,图表的代码为: >

我正在使用ggplot2从包含大约500k行的表中创建一个图表

在我的Ubuntu20.04笔记本电脑(CPU i5 8265U)上,它大约需要15秒,并在Rstudio的绘图选项卡中正确显示。现在我刚买了一台装有win 10的PC,一台更好的CPU(i5 10400F)和一个GPU(GTX 1660 Super)。同样的图表需要永远建立。如果我等待的时间足够长,我会让代码在10分钟内运行,但仍不会显示在绘图选项卡中

不幸的是,我无法共享数据,因此无法制作reprex,图表的代码为:

> 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
在win10上:

> t2 - t1
Time difference of 23.292 secs
那么主要的问题是,一个系统如何在10秒内绘制图形,而另一个系统如何在10分钟以上绘制图形?即使使用基本的graph first系统,速度也要快两倍?

是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

欢迎使用蹩脚的图形设备。在OSX上,保存为pdf然后在预览中打开pdf有时比在RStudio窗口中渲染图形要快。还有一个例子是,在一个图形设备中,文本渲染的时间比在另一个图形设备中长约300倍

我建议安装RStudio,安装软件包,然后在图形设置中将后端设置为agg:


这将为您提供良好的性能渲染。它还将解决默认Windows图形设备存在的其他一些问题,因此在任何情况下都是一个不错的选择。

谢谢,我按照您的说明操作,获得了更好的性能!小问题是,我过去用ggsave保存绘图,单位为cm,但不知何故,它不受支持(请参阅)。仅供参考,我在我的电脑上的WSL上安装了Rstudio服务器,在3秒内获得了没有ragg的绘图,因此Win10 Rstudio渲染绘图有问题。
> t2 - t1
Time difference of 23.292 secs
> 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