【发布时间】:2020-05-01 01:12:46
【问题描述】:
我在配备 8Gb RAM 的戴尔 XPS 笔记本电脑上的 Fedora 31 上运行 R。我正在尝试使用 ggplot2 绘制 this GeoTIFF,以便我可以使用我已经用 ggplot2 编写的代码覆盖其他数据。我一直在大致关注this lesson 在 R 中处理栅格数据。将 TIFF 转换为 RasterLayer 到数据帧后,R 程序在使用 ggplot2 加载数据帧时失败,只需输出“Killed”并退出。
这是产生此错误的最小代码示例:
library(tidyverse)
library(raster)
library(rgdal)
afg_pop <- raster("afg_ppp_2020.tif")
pop_df <- as.data.frame(afg_pop, xy = TRUE)
ggplot() +
# This is the line that results with the error: "Killed"
geom_raster(data = pop_df , aes(x = x, y = y, fill = afg_ppp_2020))
运行 dmesg 表明 R 内存不足:
[20563.603882] Out of memory: Killed process 42316 (R) total-vm:11845908kB, anon-rss:6878420kB, file-rss:4kB, shmem-rss:0kB, UID:1000 pgtables:19984kB oom_score_adj:0
我很难相信,即使有一个数据文件,这么大的 R 也会耗尽处理它所需的内存。为什么 R 需要这么多内存来执行这项任务,更重要的是我可以使用什么其他方法来绘制这些数据,最好使用 ggplot2?
我对 R 比较陌生,所以如果我在这里忽略了一些明显的东西,请原谅我。任何帮助将不胜感激!
【问题讨论】: