plotting and coloring data on irregular grid

前端 未结 2 1252
小鲜肉
小鲜肉 2020-12-28 09:53

I have data in the form (x, y, z) where x and y are not on a regular grid. I wish to display a 2D colormap of these data, with intensity (say, grey scale) mapped to the z va

2条回答
  •  天涯浪人
    2020-12-28 10:25

    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)))
    

    dirichlet

    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.

提交回复
热议问题