【问题标题】:Show progress of calculations in ggplot2在 ggplot2 中显示计算进度
【发布时间】:2020-08-21 02:36:43
【问题描述】:

我想知道如何在计算时显示 ggplot2 或 ggmap 操作的进度。我正在处理一些非常大的 shapefile,它们可能需要几分钟来显示绘图。我知道有几个包和函数允许您在计算期间插入进度条或百分比(例如“进度”包),但我不知道如何在 ggplot 操作中插入它。

所以,下面的例子:

library (ggplot2)
library (sf)
     
ggplot() +
  geom_sf(data = "myshapefile.shp", size = 1, color = "black", fill = "red") + 
  ggtitle("Testplot") + 
  coord_sf()

这个 shapefile 需要几分钟才能渲染成绘图。而不是只是坐在那里等待它出现而不知道它何时会完成或是否被卡住。我希望看到某种进展(条形或百分比,无关紧要 - 例如,显示何时完成 10%、20%、30% 等)。

【问题讨论】:

  • 有趣的问题。您可能需要与 ggplot 代码交互来实现这一点。类似于 pbapply 包中的 pblappy 所做的事情。
  • 进度更新需要内置到绘图函数本身中,而事实并非如此。如果不更改 ggplot 函数的源代码,您就无法做到这一点。

标签: r ggplot2


【解决方案1】:

ggplot2 的创建者 Hadley Wickham 说这里不可能有进度条。

他对简化 shapefile 的建议会将顶点移除到一定的容差,并且通常会使其渲染速度更快,而在图形中没有任何可察觉的差异。可以这样做。

library (ggplot2)
library (sf)
my_shapefile <- read_sf("myshapefile.shp")

# You'll have to test different tolerance levels here. Higher
# values will produce more rigid looking shapes which will render faster. 
# I would try values of 0.01, 0.1, 1, and 10.
my_shapefile <- st_simplify(my_shapefile, dTolerance = 0.1)

ggplot() +
  geom_sf(data = my_shapefile, size = 1, color = "black", fill = "red") + 
  ggtitle("Testplot") + 
  coord_sf()

【讨论】:

    猜你喜欢
    • 2020-01-22
    • 1970-01-01
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多