如何使用R在一个帧中放置多个层?

如何使用R在一个帧中放置多个层?,r,overlay,layer,R,Overlay,Layer,我用R来绘制地图文件 setwd("c:\\apa\\") # Load libraries library("maptools") library("RColorBrewer") library("classInt") library("R2wd") library("Hmisc") library("plyr") library("ggplot2") library("rgdal") file.path <- "c:\\apa\\" file.name <- "apa_plan

我用R来绘制地图文件

setwd("c:\\apa\\")
# Load libraries
library("maptools")
library("RColorBrewer")
library("classInt")
library("R2wd")
library("Hmisc")
library("plyr")
library("ggplot2")
library("rgdal")

file.path <- "c:\\apa\\"
file.name <- "apa_planalto_central"
apa <-readShapePoly(paste(file.path,file.name,sep=""))

file.name <- "AUTORIZACAO_09889652011"
auth <-readShapePoly(paste(file.path,file.name,sep=""))

file.name <- "CLIP_HIDROGRAFIA_APA"
hidro <-readShapeLines(paste(file.path,file.name,sep=""))

file.name <- "ferrovias"
ferrovias <-readShapeLines(paste(file.path,file.name,sep=""))

file.name <- "lagos_df"
lagos <-readShapePoly(paste(file.path,file.name,sep=""))

file.name <- "limite_df"
limites <-readShapeLines(paste(file.path,file.name,sep=""))

file.name <- "rodovias"
rodovias <-readShapeLines(paste(file.path,file.name,sep=""))


plot(apa)
plot(...)
setwd(“c:\\apa\\”)
#加载库
库(“地图工具”)
图书馆(“RColorBrewer”)
图书馆(“classInt”)
图书馆(“R2wd”)
图书馆(“Hmisc”)
图书馆(“plyr”)
图书馆(“ggplot2”)
图书馆(“rgdal”)

file.path您可以使用如下内容:

plot(apa)
plot(auth, add=T)

只需在
plot()
函数中使用
add=T

您可以使用如下内容:

plot(apa)
plot(auth, add=T)

只需在
plot()
函数中使用
add=T

在ggplot2中,您可以堆叠多个几何图形。这大概是:

ggplot(aes(x = x, y = y), data = pointset1) +
  geom_point() +
  geom_polygon(aes(fill = z), data = polyset1) +
  etc

这假设所有数据集都位于同一投影中,所有数据集都使用列名x表示x坐标等。请注意,ggplot2适用于data.frames,而不是sp对象。使用函数fortify将空间多边形对象转换为data.frame。

在ggplot2中,可以堆叠多个几何图形。这大概是:

ggplot(aes(x = x, y = y), data = pointset1) +
  geom_point() +
  geom_polygon(aes(fill = z), data = polyset1) +
  etc
这假设所有数据集都位于同一投影中,所有数据集都使用列名x表示x坐标等。请注意,ggplot2适用于data.frames,而不是sp对象。使用函数fortify将空间多边形对象转换为data.frame