Using the R language to draw the Chicago vector map _r language

Source: Internet
Author: User
Yesterday, a student at the Southern University of the city planning on Sina Weibo @ I,

By that he means to convert the JSON data to vector graphics, I didn't hear a good switch before, and I saw that Chicago really put the city planning data on the GitHub, see here: http://thechangelog.com/ the-city-of-chicago-is-on-github/

Choose one of them at random, I choose bike here.
Routes in Chicago, you can see the items above GitHub, including data and examples. In the readme.md surprised discovery can also use the R language to draw, just want to learn r language, so a small try. It is worth mentioning that the author has written in detail the steps in the document, follow the steps step by step.

# 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 are need to Install the Rgdal and GGPLOT2, libraries  Ete This step, otherwise, skip:install.packages (C ("Rgdal", "Ggplot2")) library (rgdal) # Import data into a Spatial Data frame in R library (GGPLOT2) # Transform data ' Shapefile to ' data frame # Import data to Spatial dataframe Ogrin Fo ("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 DA

TA structure.

Plot (bikeroutes.shapefile) # Test plot of spatial data frame. # fortify Data to translate to data Frame bikeroutes.df <-fortify (bikeroutes.shapefile) # Caution, this is very memory Intensiv E and may take several hours to complete head (BIKEROUTES.DF) # Inspect The data structure Ggplot (BIKEROUTES.DF, AES (X=lo Ng, Y=lat, Group=group)) + Geom_path () # Test plot of data frame.

Data in the GitHub project in the database folder, CSV data download can be, the resulting results are 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.