0

I am using the following map: https://gist.github.com/simzou/6459889#file-nielsentopo-json to plot the DMA regions.

I tried following along on this previous stackoverflow[https://stackoverflow.com/questions/35493585/r-import-html-json-map-file-to-use-for-heatmap], however the fortify command doesn't work and I can't figure out why:

library(sp)
library(rgdal)
library(maptools)
library(rgeos)
library(ggplot2)
library(ggalt)
library(ggthemes)
library(jsonlite)
library(purrr)
library(viridis)
library(scales)

neil <- readOGR("~nielsentopo.json", "nielsen_dma", stringsAsFactors=FALSE,  verbose=FALSE)
# there are some techincal problems with the polygon that D3 glosses over
neil <- SpatialPolygonsDataFrame(gBuffer(neil, byid=TRUE, width=0),
                                  data=neil@data)
neildf <- as.data.frame(neil)
neil_map <- fortify(neil, region = 'id')

This is the error I receive:

Too few points in geometry component at or near point -82.061259930000006 26.499350110000002Ring Self-intersection at or near point -89.1404651 29.135150639999999Ring Self-intersection at or near point -78.518767870000005 33.867667130000001SpP is invalid
Invalid objects found; consider using set_RGEOS_CheckValidity(2L)Error in rgeos::gUnaryUnion(spgeom = SpP, id = IDs) : 
  TopologyException: Input geom 0 is invalid: Ring Self-intersection at or near point -78.518767870000005 33.867667130000001 at -78.518767870000005 33.867667130000001

Can you help?

Sheila
  • 2,438
  • 7
  • 28
  • 37

1 Answers1

0

Got the answer! broom:tidy is suggested instead of fortify now. In addition, follow the logic here for the rest and you'll be good to go:

keep region names when tidying a map using broom package

Sheila
  • 2,438
  • 7
  • 28
  • 37