2016-05-17 69 views
0

我想绘制我的报告的等值线图。我已经从GADM下载了数据。我成功绘制了等值线图,但是当我添加边界时,发生了错误。出现了很多蓝线。在R中绘制省界线

我的代码是:

#Read Database 
HCM <- read.csv("HCM.csv") 

#Load Packages 
library(plyr) 
library(sp) 
library(ggplot2) 
library(rgeos) 
library(maptools) 
library(scales) 

#Read Map (Map downloaded from GADM) 
vie_map1 <- readRDS('VNM_adm1.rds') 
vie_map <- fortify(vie_map1, region = "ID_1") 

#Draw the map 
ggplot() + 
    geom_map(data = HCM, aes(map_id = ID, fill = WeightRange), 
      map = vie_map) + expand_limits(x = vie_map$long, y = vie_map$lat) 

I want this

但是,当我想补充的界限,一些错误的发生(蓝色直线)。添加边界的代码是:

# Add the boundaries 
ggplot() + 
    geom_map(data = HCM, aes(map_id = ID, fill = WeightRange), 
      map = vie_map) + expand_limits(x = vie_map$long, y = vie_map$lat)+ 
geom_path() + 
    geom_path(data = vie_map, aes(x = long, y = lat), color = "blue") + 
    theme_bw() 

请告诉我如何解决它(删除直线)。

I got this

+0

您可以查看:http://stackoverflow.com/questions/19718814/how -to-拉ggmap与 - 两个不同的行政,边界 – Technophobe01

回答

0

同时设定groupgeom_path美学映射中,不仅xy

library(ggplot2) 
library(raster) 
library(maptools) 
vie_map1 <- getData("GADM", country="VNM", level=1) 
# trying URL 'http://biogeo.ucdavis.edu/data/gadm2.8/rds/VNM_adm1.rds' 
# Content type '' length 2765340 bytes (2.6 MB) 
# downloaded 2.6 MB 
vie_map <- fortify(vie_map1, region = "ID_1") 
ggplot() + 
    geom_polygon(data = vie_map, aes(x = long, y = lat, group = group), fill = "grey90") + 
    geom_path(data = vie_map, aes(x = long, y = lat, group = group), color = "blue") + 
    theme_bw()