我正在尝试制作一些不列颠群岛的地图,但遇到了一个非常奇怪的记忆问题。我的工作流程是利用 ggplot 的图层在底图上添加新的细节。
底图本身从GADM获取英国和爱尔兰的形状文件,简化了thinnedSpatialPoly
MapTools 中使用的几何图形,从而产生了这张地图:
然后对于后续图层,我做同样的事情:加载 SHP 文件,简化几何并将其添加到基础地图,如下所示:
# new_data is a SpatialPolygonsDataFrame
base_map + geom(data=new_data, color="black", fill=my_fill)
对于大多数地图,我都做得很好。但是,当我尝试添加一个特定层时,R 冻结并最终给我以下错误:
Error: cannot allocate vector of size 86.9 Mb
In addition: Warning messages:
1: In data.frame(x = x, y = y, aes_df) :
Reached total allocation of 3953Mb: see help(memory.size)
2: In data.frame(x = x, y = y, aes_df) :
Reached total allocation of 3953Mb: see help(memory.size)
3: In as.data.frame.numeric(x[[i]], optional = TRUE) :
Reached total allocation of 3953Mb: see help(memory.size)
4: In as.data.frame.numeric(x[[i]], optional = TRUE) :
Reached total allocation of 3953Mb: see help(memory.size)
5: In as.data.frame.numeric(x[[i]], optional = TRUE) :
Reached total allocation of 3953Mb: see help(memory.size)
6: In as.data.frame.numeric(x[[i]], optional = TRUE) :
Reached total allocation of 3953Mb: see help(memory.size)
生成此图的代码与上面完全相同。如果我自己绘制新图层,例如
ggplot(new_data, aes(x=long, y=lat, group=group)) + geom_polygon
那么就没有问题了,地图绘制得非常快。对于磁盘上的参考,形状文件为 769 KB,而其他层为 248 KB。
我不知道如何调试和解决这个问题。任何指针都会很棒 - 谢谢!