如何在R中绘制多个多边形图?

问题描述:

我正在使用R绘制多边形

I am plotting polygon using R

yy<-c(1217,2343,3255,2129)
xx<-c(61587690.5,61588253.5,61587797.5,61587234.5)
polygon(xx, yy, col="gray", border = "red")

但是我想向同一图表添加100000个多边形图.如何将全部添加到一张图表中.

But i want to add 100000 polygon plots to the same chart. How can i add all into one chart.

下面是使用坐标列表列表的示例.它将同一区域中的所有多边形都绘制出来(我想问的是它们对您有多清晰……)

Here's an example using a list of lists of coordinates. It plots all polygons in the same plot (I leave the question of how discernible they are to you...)

#generate some data
set.seed(123)
n=10
#each 'polygon' is inside a list with xx and yy coordinates
dat <- lapply(1:n,function(x){
  res <- list(xx=c(1,2,3,2)+rnorm(4),
              yy=c(1,2,3,2)+rnorm(4))
  return(res)
})

#create empty plot
plot(0:5,0:5,type='n')
#add polygons
lapply(dat,function(x){polygon(x$xx,x$yy,col="gray",border="red")})