我正在尝试从名为data
的数据框中绘制这些国家:
country value lon lat
1 Denmark 12 9.501785 56.263920
2 UK:Great Britain 13 -1.174320 52.355518
3 France 15 2.213749 46.227638
4 Germany 17 10.451526 51.165691
5 China:Hong Kong 18 114.174695 22.278315
6 Netherlands 31 5.291266 52.132633
7 New Zealand 32 174.885971 -40.900557
8 UK:Northern Ireland 33 -6.492314 54.787715
9 Norway 34 8.468946 60.472024
10 Saudi Arabia 40 45.079162 23.885942
11 Serbia 41 21.005859 44.016521
12 Singapore 42 103.819836 1.352083
13 Slovak Republic 43 101.724578 3.153870
14 Slovenia 44 14.995463 46.151241
15 South Africa 45 22.937506 -30.559482
我正在使用worldmap和ggplot库:
library(maps) # Provides functions that let us plot the maps
library(ggplot2) # Generic graphis engine
map = map_data("world")
map = subset(map, region!="Antarctica") #Remove Antarctica from map
Countries = ggplot() +
geom_polygon(data = map, aes(x=long, y = lat, group = group), fill = NA, colour="darkgray", size=0.5)+
geom_map(data=data,map=map,aes(map_id=country, x=lon, y=lat),fill = "cornflowerblue", colour = "gray") +
coord_equal()
Countries
我可以绘制除了 UK:Great Britain
, China: Hong Kong
以及所有其他的区域和子区域都用 ":" 分隔的国家地图:
我不知道如何使用 world_map 和 ggplot 绘制 UK:Great Britain
的地图。你们有没有遇到类似的问题或者有解决方案?谢谢。
map = map_data("world") map = subset(map, region!="Antarctica") write.table(map, "C:/temp/map.txt", sep=";")
。然后在Excel中连接区域和子区域列(其中子区域不为NA),并将保存的CSV文件重新导入R中。map <- read.csv("c:/Temp/map.csv", sep=";")
- JPMD