绘制Shapefile rgdal ggplot额外的线条绘图?

时间:2016-06-14 01:04:19

标签: r ggplot2 kml shapefile rgdal

我试图为雨水添加雨水。我已成功绘制了点等等,并通过使用GISconverter将{kml}转换为shapefile并在绘制Shapefile多边形后跟随this turorial来完成。然而,当我绘制图表时,我会得到额外的线条。他们似乎是一个回归原点'线。我在this image中用蓝色箭头指出了一些。 enter image description here 但是,我不确定这是否是原因,我已在Google Maps中绘制地图数据,以检查映射及其正确性。 请参阅下面的代码;此处还有Google Drive share folder包含所有代码和数据集等(文件上传可能需要一些时间)。

非常感谢任何帮助,我对使用kml或任何地理/地图文件的经验不多。 提前谢谢。

`### BVB313
library(ggrepel)
###MAPS
#Read in Map.cvs
P.Map<- read.csv(file = file.choose())
myLocation <- c( lon = 152.911033,lat = -27.344505)
#get map
myMap <-get_map(location=myLocation,source="google", color="color",zoom = 9, maptype = c("terrain"))
ggmap(myMap)
#plot map with points
P.out<-ggmap(myMap)+ 
  #geom_polygon(aes(x=long, y=lat), size=1,color='red', data=Neighborhoods, alpha=0)+
  geom_point(aes(x = Longitude, y = Latitude), data = P.Map,
  alpha = .5, color="darkred", size = 3) +
  geom_label_repel(data=P.Map,aes(x = Longitude, y = Latitude, label = Location),nudge_x = 0.20,nudge_y = -0.025)+ 
  labs(title = "Sampling Locations", x = "Longitude", y = "Latitude")+
  theme(plot.title = element_text(size=15, face="bold", vjust=2)) +
  annotate("text", x = 152.25, y = -28, label = "10km", hjust=-0.1, vjust=-0.2)+
  annotate("segment", x = 152.25, xend = 152.25, y = -27.91, yend = -28, size = 1.5) 
P.out

#ggsave(filename = "BW Map.png" ,plot = P.out, width = 8,height = 8,dpi =600,units = "in" )

# Catchment Area Shape File Layer
#set directory to working location!!!!
########################
install.packages('rgdal')
install.packages('ggplot2')
library(rgdal)
catchment_layer <- readOGR(".","polylines5")
catchment_layer <- spTransform(catchment_layer, CRS("+proj=longlat +datum=WGS84"))

library(ggplot2)

catchment_layer <- fortify(catchment_layer)
P.out_catchment_layer <- P.out + geom_polygon(aes(x=long, y=lat), size=.2,color='red', data=catchment_layer, alpha=0)
P.out_catchment_layer
ggsave(filename = "Catchment_Map.png" ,plot = P.out_catchment_layer, width = 8,height = 8,dpi =600,units = "in" )`

0 个答案:

没有答案