plotting and coloring data on irregular grid

帅比萌擦擦* 提交于 2019-11-30 02:23:14

Here's a solution based on dirichlet from the maptools package,

d <- data.frame(x=runif(1e3, 0, 30), y=runif(1e3, 0, 30))
d$z = (d$x - 15)^2 + (d$y - 15)^2

library(spatstat) 
library(maptools)

W <- ripras(df, shape="rectangle") 
W <- owin(c(0, 30), c(0, 30)) 
X <- as.ppp(d, W=W) 
Y <- dirichlet(X) 
Z <- as(Y, "SpatialPolygons") 
plot(Z, col=grey(d$z/max(d$z)))

I'm still unsure of the way to extract the polygons from this SpatialPolygons class.

Also if there's an easy way to produce the "correct" colors for the associated delaunay tesselation I'd like to hear it.

Here is a lattice solution using deldir

d <- data.frame(x=runif(1e3, 0, 30), y=runif(1e3, 0, 30))
d$z = (d$x - 15)^2 + (d$y - 15)^2

pal1 <- grey(seq(0,1,leng=500))
library(latticeExtra)

 levelplot(z~x*y, data=d,
           panel = function(...) panel.voronoi(..., points=FALSE),
           interpolate=TRUE,
           col.regions = colorRampPalette(pal1)(1e3), cut=1e3)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!