plotting and coloring data on irregular grid

前端 未结 2 1250
小鲜肉
小鲜肉 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:18

    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)
    

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题