服务热线
178 0020 3020
>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")
> 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
附件