Use the r language to draw a Chicago vector chart

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.