I have found myself with a data.frame containing a column of lists. Within these lists are the coordinates for a polygon; the remainder of the columns are the features of the polygons.
I would like to "spread out" the coordinate points in the lists so that I can use ggplot2
to plot the polygons and make a map, but am having trouble figuring out how to do this.
I don't really understand how the lists are structured and they are all different sizes, as the polygons have different shapes.
The data was originally a json file. I pulled it in with jsonlite
package and then tried to boil it down to the relevant components like so:
library(jsonlite)
json_file <- "https://raw.githubusercontent.com/OpenOil-UG/concessionsmap/master/concessions/data/NG_contracts%2B.geojson"
json_data <- jsonlite::fromJSON(json_file, simplifyDataFrame=T)
data <- json_data$features
data2 <- flatten(data)
This may not be the right approach starting with the json file. It is just what seemed most straightforward to me as far as taking the data from json to a data.frame I could understand.
*Edited to include real data instead of a sample