1

这是多边形坐标:

# 数据

greenM <-matrix(c(5,5,95,45,5,65,5,45,65,5,5,95),nrow=4,byrow=TRUE)
blueM <-matrix(c(35,15,65,35,45,35,5,75,35,5,45,65,35,15,65),
 nrow=5,byrow=TRUE)
purpleM <-matrix(c(95,5,15,95,5,5,35,75,5,35,45,35,55,45,15,95,5,15),
  nrow=6,byrow=TRUE)
redM <-matrix(c(35,45,35,35,75,5,5,95,5,5,75,35,35,45,35),
 nrow=5,byrow=TRUE)
yellowM <-matrix(c(95,5,15,45,5,65,35,15,65,35,45,35,55,45,
15,95,5,15),nrow=6,byrow=TRUE)

这是情节(未循环,但我想用 short 自动化长代码,以便可以用 x 数量的颜色生成 x 数量的情节)

plot(NA,NA,xlim=c(0,10),ylim=c(0,100),asp=1,bty="n",axes=F,xlab="",ylab="")
polygon(greenM,col="green",border=NULL)
polygon(blueM,col="blue",border=NULL)
polygon(purpleM,col="purple",border=NULL)
polygon(redM,col="red",border=NULL)
polygon(yellowM,col="yellow",border=NULL)

我怎样才能创建这样的外观,它将按顺序应用于具有不同颜色的坐标列表。

mycolist <- list (greenM, blueM, purpleM, redM, yellowM)
col1 <- c("green", "blue", "purple", "red", "yellow")
4

1 回答 1

2

查看mapply

mycolist <- list (greenM, blueM, purpleM, redM, yellowM)
col1 <- c("green", "blue", "purple", "red", "yellow")
plot(NA,NA,xlim=c(0,10),ylim=c(0,100),asp=1,bty="n",axes=F,xlab="",ylab="")
mapply(polygon,x=mycolist,col=col1)

如果您不想将所有NULL输出都显示到屏幕上,只需将其包装在invisible.

invisible(mapply(polygon,x=mycolist,col=col1))
于 2012-07-30T18:51:55.493 回答