R2-16-地图作业

fjh19881216 2018-01-02 12:14:00 阅读: 1061

>install.packages("rgdal")

>install.packages("maptools")

>library(ggplot2)

>library(maptools)

>library(rgdal)

>library(plyr)

> setwd("F:/R语言学习/R2-9-地图绘图3")

> mytheme_map <- theme(panel.grid = element_blank(),panel.background = element_blank(),axis.text = element_blank(),axis.ticks = element_blank(),axis.title = element_blank())

> china_map<-readShapePoly("bou2_4p.shp")

> china_map = readOGR(dsn = "bou2_4p.shp",stringsAsFactors=FALSE)

> x <- china_map@data

> xs <- data.frame(x,id=seq(0:924)-1)

> china_map1 <- fortify(china_map)

> china_map_data <- join(china_map1, xs, type = "full")

> p<-ggplot(fujian_map_data, aes(x = long, y = lat, group = group,fill=NAME))+geom_polygon(fill="pink")+geom_path(colour = "grey40")+geom_point(x=117.01,y=25.06,fill="red")+annotate("text",x=117,y=25,label="CC's location: longyan")

> p+mytheme_map+ggtitle("R2-16")

第一题.png

> mydata <- read.csv("R2-9.csv")

> mydata <- as.data.frame(mydata)

> china_data <- join( mydata, china_map_data,type="full")

> ggplot(china_data, aes(x = long, y = lat, group = group, fill = pop)) +geom_polygon(colour="green") +scale_fill_gradient(low="white",high="red") +coord_map("polyconic") +ggtitle("R2-16")+mytheme_map

第二题.png

 
邀请讨论

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
{{item.nick_name}} 受邀请回答 {{item.create_time}}
{{item.refer_comment.nick_name}} {{item.refer_comment.create_time}}

附件

{{f.title}} 大小 {{f.file_size}} 下载 {{f.count_download}} 金币 {{f.count_gold}}
切换到完整回复 发送回复
赞({{item.count_zan}}) 踩({{item.count_cai}}) 删除 回复 关闭
科研狗©2015-2024 科研好助手,京ICP备20005780号-1 建议意见

服务热线

178 0020 3020

微信服务号