Every R point: All kinds of painting maps, all knowledge points, 90% people do not know!

Source: Internet
Author: User
Tags ggplot

The R language draws maps, which are often used in data analysis and can achieve very good results, and this section provides examples of how to use the R language tools to draw the ideal map.

Examples of this section run smoothly under the R version 2.15.3 release, and other versions are pending.

The code is as follows: The first small example

# load the appropriate package, read the data, and then draw.  Library (maptools), library (Ggplot2), China_map<-readshapepoly ("d://map//bou2_ 4p.shp", Proj4string=crs ("+proj=longlat +ellps=clrk66")); Plot (china_map);

Use Ggplot to draw below.

Ggplot (China_map, AES (x = long, y = lat, group = group)) +   "beige") +   "grey40");

Draw a better-looking map, how!

X<[email protected];#S4 class data with @ Fetch subsetXs<-data.frame (X,id=seq (0:924)-1);#Library (GGPLOT2)China_map1<-fortify (CHINA_MAP);#Convert to Data frame#There is no administrative area information Ah, this requires the front of the data frame XS. library (PLYR); China_mapdata<-join (CHINA_MAP1, xs, type =" Full");#merging two data frames#Use this new data frame to draw a map of ChinaGgplot (China_mapdata, AES (x = long, y = lat, group = group,fill=name)) +geom_polygon () +geom_path (colour ="grey40")+scale_fill_manual (Values=colours (), guide=false);

and draw a map of the city's regional type.

Zhejiang<-subset (china_mapdata,name=="Zhejiang province"); Ggplot (Zhejiang, AES (x= long, y = lat, group = group,fill=name) +Geom_polygon (Fill="Beige")+Geom_path (Colour="grey40")+Ggtitle ("Zhejiang Province, P.R. China")+geom_point (x=120.12,y=30.16,fill=false) +Annotate ("text", x=118.3,y=30,label="Hangzhou City");

Focus Point:

⊙ above is only introduce several kinds of drawing method. In addition, there are more map functions, you can look for friends. For specific parameters and corresponding indicators in the map, you can use R to bring your own Help document to view.

Transferred from: http://mp.weixin.qq.com/s?__biz=MzA3NDUxMjYzMA==&mid=209747952&idx=2&sn= 72725a5801c0b1c14a7da6cc7e68719c#rd

Every R point: All kinds of painting maps, all knowledge points, 90% people do not know! Go

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.