Yesterday, a student who planned a city in South University asked me on Sina Weibo
He converted JSON data into a vector image. I have never heard of this conversion before. I went to the website and checked it, the discovery of Chicago really put the city planning data on GitHub, see here: http://thechangelog.com/the-city-of-chicago-is-on-github/
Select one of them at will. Here I select bike
Routes in Chicago, you can see the projects on GitHub, including data and examples. In readme. md, I was surprised to find that I could use the r language to draw the image. I just wanted to learn the r language, so I tried it. It is worth mentioning that the author has carefully written the operation steps in this document. Follow these steps to do so.
# Title: importing geojson example in R # Author: Tom Schenk jr ., city of Chicago # created: 2013-01-23 # updated: 2013-01-31 # Notes: # libraries: rgdal, ggplot2 # set working directory (e.g ., "C: \ Users \ USERNAME \ downloads" or "~ /Downloads ") setwd (" path \ To \ folder ") # Install and load libraries # If you need to install the rgdal and ggplot2 libraries, complete this step first, otherwise, Skip: Install. packages (C ("rgdal", "ggplot2") Library (rgdal) # import data into a spatial data frame in rlibrary (ggplot2) # transform data from shapefile to data frame # import data to spatial dataframeogrinfo ("data \ bikeroutes. JSON ", layer =" ogrgeojson ") bikeroutes. shapefile <-readogr (DSN = "data \ bikeroutes. JSON ", layer =" ogrgeojson ", p4s =" + proj = tmerc + ellps = WGS84 ") # imports data. replace path \ To with actual file path (e.g ., c: \ Users \ USERNAME \ downloads) Head (bikeroutes. shapefile) # inspect the data structure. plot (bikeroutes. shapefile) # test plot of spatial data frame. # foreach data to translate to data framebikeroutes. DF <-Fortes (bikeroutes. shapefile) # caution, this is very Memory Intensive and may take several hours to completehead (bikeroutes. DF) # inspect the data structureggplot (bikeroutes. DF, AES (x = long, y = Lat, group = Group) + geom_path () # test plot of data frame.
Download the CSV data in the data folder of the GitHub project. The final result is as follows: