2016-05-17 73 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()