在R中绘制多个图层

时间:2017-07-14 15:58:01

标签: r plot geospatial spatial

我正在尝试将多个空间图层绘制到一个地图上。我无法将我的积分带到美国地图上。我正在使用ggplot来映射这些空间数据。在命令add = TRUE时遇到问题,将点(坐标)添加到“midwst”地图上。我可以分别绘制两个,但可以使用一些帮助在地图上方获取坐标。我觉得我可能没有使用正确的包命令,但无法分辨。

setwd("D:")

midwst <- readOGR(dsn="/ne_50m_states", layer="us")
fsites = read.csv(file = "/WHAT Baseflow//final_sites.csv", header=T, 
sep=",")

#Identify pts and Change projection

coords <- SpatialPoints(fsites[,c("Longitude", "Latitude")])

projection(coords) <- CRS("+init=epsg:2163")
spTransform(coords,CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 
+towgs84=0,0,0"))

#Extract States from US Map
plot(midwst, axes = T)
plot(coords, pch = 21, bg = "red", cex = .5, axes = T)

1 个答案:

答案 0 :(得分:-1)

以下是使用R基本方法绘制多个图层的示例

# Import "raster" package
library(raster)
# Get "Vietnam" from online database called GADM
HN<-getData(name = "GADM",country="Vietnam",level=0)

# Plotting HN map
par(mar=rep(2,4))
plot(HN,border="black",axes=T)

# Create some sample coordinates

df<-data.frame(x=seq(105,106,by=0.5),y=seq(20,21,by=0.5))

library(sp)
# Building a spatial point object
coordinates(df)<-~x+y

proj4string(df)<-CRS("+proj=longlat +datum=WGS84")

# Overlaying the spatial point object on Vietnam map
plot(df,add=T,col=2)