繪製世界指定區域的地圖數據
#install.packages("maps")
library(maps)
library(ggplot2)
world_map <- map_data("world")
euro <- map_data("world", region = c("UK","France", "Spain","Germany", "Italy"))
ggplot(euro, aes(x=long, y = lat, group=group,fill=region)) + geom_polygon(colour="black") + scale_fill_brewer(palette = "Set2") + scale_y_continuous(limits=c(40,60)) + scale_x_continuous(limits=c(-25,25)) + labs(title = " Euorpes Big Five Football Leagues")
美國省份地圖繪製
安裝包準備
#install.packages(“maps”)
library(maps)
library(ggplot2)
調出美國的國家地圖
states_map <- map_data(“state”)
查看美國國家地圖數據的區域
table(states_map$region)
提取美國國家地圖省份的數據
euro <- map_data(“state”, region = c(“new york”,“vermont”,
“new hampshire”,“massachusetts”, “connecticut”))
ggplot繪製省份地圖的數據
ggplot(euro, aes(x=long, y = lat, group=group,fill=region)) +
geom_polygon(colour=“black”) +
scale_fill_brewer(palette = “Set2”) +
labs(title = " Euorpes Big Five Football Leagues")
中國省份地圖繪製
library ( maps )
library ( mapdata )
setwd("C:\\Users\\Administrator\\Desktop\\map")
data=read_excel("PMDiff2017.xlsx")
map ( "china" , col = "darkgray" , ylim = c ( 18 , 54 ) , panel.first = grid ( ) )
points ( data$slon , data$slat, pch = 19 , col = rgb ( 0 , 0 , 0 , 0.5 ) )