服务热线
178 0020 3020
###week 9 code
setwd("D:/projects/R learning/week 9 data")
library(maptools)
library(ggplot2)
library(plyr)
china_map <- readShapePoly("bou2_4p.shp")
plot(china_map, axes=TRUE, border="gray")
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")
yunnan <- subset(china_map_data, NAME == "云南省")
mytheme<-theme( panel.background=element_blank(),
panel.grid=element_blank(),
axis.text=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(), legend.position = "none")
ggplot(yunnan, aes(x = long, y = lat, group = group,fill=NAME))+
geom_polygon(fill="purple" )+
geom_path(colour = "grey40")+
ggtitle("R2-38-云南-昆明")+
geom_point(aes(x=102.42,y=25.04),colour="white",size=3,pch=19)+
geom_text(mapping = aes(x=103.42,y=26.04,label=NAME),color="black",cex=5)+
annotate("text",x=102.7,y=25,label="昆明", color = "white")+
mytheme
pop <- read.csv("R2-9-1.csv")
china_pop<-join(china_map_data, pop, type = "full")
ggplot(china_pop, aes(x = long, y = lat, group = group,fill=pop))+
geom_polygon( )+
scale_fill_gradient(low="white",high="red")+
geom_path(colour = "green")+
ggtitle("R2-38")+
mytheme
附件