简体   繁体   English

在地图上用ggplot2 R绘制多边形的多边形

[英]Choropleth Plotting polygons with ggplot2 R on a map

I realise this has been asked about 100 times prior, but none of the answers I've read so far on SO seem to fit my problem. 我意识到这个问题之前已经被问过100次了,但是到目前为止,我所读的答案似乎都不适合我的问题。

I have data. 我有资料 I have the lat and lon values. 我有纬度和经度值。 I've read around about something called sp and made a bunch of shape objects in a dataframe. 我已经阅读了有关sp的内容,并在数据框中制作了一堆形状对象。 I have matched this dataframe with the variable I am interested in mapping. 我已将此数据框与我对映射感兴趣的变量匹配。

I cannot for the life of me figure out how the hell to get ggplot2 to draw polygons. 我一生都无法弄清楚如何使ggplot2绘制多边形。 Sometimes it wants explicit x,y values (which are a PART of the shape anyway, so seems redundant), or some other shape files externally which I don't actually have. 有时,它需要显式的x,y值(无论如何都是形状的一部分,因此看起来很多余),或者需要一些我实际上没有的外部形状文件。 Short of colouring it in with highlighters, I'm at a loss. 没有用荧光笔着色,我很茫然。

if I take an individual sps object (built with the following function after importing, cleaning, and wrangling a shitload of data) 如果我使用一个单独的sps对象(在导入,清理和整理大量数据之后使用以下函数构建)

createShape = function(sub){
  #This funciton takes the list of lat/lng values and returns a SHAPE which should be plottable on ggmap/ggplot
  tempData = as.data.frame(do.call(rbind, as.list(VICshapes[which(VICshapes$Suburb==sub),] %>% select(coords))[[1]][[1]]))
  names(tempData) = c('lat', 'lng')
  p = Polygon(tempData)
  ps = Polygons(list(p),1)
  sps = SpatialPolygons(list(ps))
  return(sps)
}

These shapes are then stored in the same dataframe as my data - which only this afternoon for some reason, I can't even look at, as trying to look at it yields the following error. 然后将这些形状存储在与我的数据相同的数据框中-只是由于某种原因,直到今天下午我什至都看不到它,因为尝试查看它会产生以下错误。

head(plotdata)
Error in prettyNum(.Internal(format(x, trim, digits, nsmall, width, 3L,  : first argument must be atomic

I realise I'm really annoyed at this now, but I've about 70% of a grade riding on this, and my university has nobody capable of assisting. 我意识到我现在对此感到非常恼火,但是我已经获得了大约70%的成绩,而且我的大学没有人能够提供帮助。

I have pasted the first few rows of data here - https://pastebin.com/vFqy5m5U - apparently you can't print data with an s4 object - the shape file that I"m trying to plot. 我在这里粘贴了前几行数据-https: //pastebin.com/vFqy5m5U-显然您无法使用s4对象(我要绘制的形状文件)打印数据。

Anyway. 无论如何。 I'm trying to plot each of those shapes onto a map. 我正在尝试将每个形状绘制到地图上。 Polygons want an x,y value. 多边形需要x,y值。 I don't have ANY OTHER SHAPE FILES. 我没有其他任何形状的文件。 I created them based on a giant list of lat and long values, and the code chunk above. 我根据大量的lat和long值以及上面的代码块创建了它们。 I'm genuinely at a loss here and don't know what question to even ask. 我在这里真的很茫然,甚至都不知道要问什么问题。 I have the variable of interest based on locality, and the shape for each locality. 我有基于位置的兴趣变量,以及每个位置的形状。 What am I missing? 我想念什么?

edit: I've pasted the summary data (BEFORE making them into shapes) here. 编辑: 我已经在此处粘贴摘要数据(在将它们制成形状之前)。 It's a massive list of lat/lng values for EACH tile/area, so it's pretty big... 这是每个图块/区域的大量经度/纬度值列表,因此它很大...

gis.stackexchange.com回答 (未提供链接)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM