a friend referred me here as opposed to the regular Stack Overflow site, as this community maybe better able to help!
My issue is largely with the syntax and framework of ggmap
,ggplot
, and the sp
package.
I have already summarised and prepped my data. This link shows (some of) the data I'm trying to map. I used the following code block to create Spatial polygon objects instead of lists of lat/long values, as shown in the data in the above link:
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)
}
VICshapes[['shape']] = lapply(suburbNames, function(x) createShape(x))
So - I've got the data I want to plot. I've got shapes. I've got the packages installed... but how do I actually make things look pretty and presentable? ANY of the help on packages seems to assume I have .shp files, along with other external data which defines how I plot it all. Apparently I need to use ggmap::fortify()
or broom::tidy
on the shape files to get them to plot. Then I just get warnings from ggmap
and ggplot
about the length of aes arguments being incorrect.
I'm genuinely not sure how to proceed with this, but I know I have the necessary data to show what I want to show - I just don't know how to move forward.
Using R's inbuilt plot
function on the output of the createShape()
function above shows me a shape as I want. Great - but what if I want ALL the shapes, then coloured according to another variable - which is linked by a common key?
At this stage I'm so frustrated with it all - I'll literally pay someone's rent for a month if you can help.