2016-05-17 13 views
0

私のレポートのためにchoroplethマップを描きたい。 GADMからデータをダウンロードしました。私はchoroplethの地図を描くことに成功しましたが、私が境界を追加したとき、何か間違いが起こりました。青い線がたくさん現れます。州の境界を描く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 2つの異なる管理境界を持つggmap-to-draw-ggmap – Technophobe01

答えて

0

はまたgeom_pathxyないだけの美学マッピング内groupを設定します。

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() 
関連する問題