Coloring Dirichlet Tiles

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Coloring Dirichlet Tiles

awesolow
Hi,

I have a set of x, y points (longitude/latitude) along with a z value representing an attribute at each point.  I want to create a Voronoi/Dirichlet tesselation of these points coloring each tile by the z value.  I tried searching for a way to solve this and it was suggested to use the dirichlet() command to get the correct coloring.  However, my coloring is not correct.

Any thoughts?

Thanks in advance.
Reply | Threaded
Open this post in threaded view
|

Re: Coloring Dirichlet Tiles

baptiste auguie-5
Hi,

Try this,

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

and also panel.voronoi in latticeExtra.

Unfortunately I do not know of a solution that uses more efficient
algorithms for computing the Dirichlet tessellation and extracting
tiles than those relying on deldir. The Triangle package (r-forge)
looks promising.

HTH,

baptiste


On 5 September 2011 06:26, awesolow <[hidden email]> wrote:

> Hi,
>
> I have a set of x, y points (longitude/latitude) along with a z value
> representing an attribute at each point.  I want to create a
> Voronoi/Dirichlet tesselation of these points coloring each tile by the z
> value.  I tried searching for a way to solve this and it was suggested to
> use the dirichlet() command to get the correct coloring.  However, my
> coloring is not correct.
>
> Any thoughts?
>
> Thanks in advance.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Coloring-Dirichlet-Tiles-tp3789746p3789746.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Coloring Dirichlet Tiles

Rolf Turner-3
In reply to this post by awesolow
On 05/09/11 06:26, awesolow wrote:

> Hi,
>
> I have a set of x, y points (longitude/latitude) along with a z value
> representing an attribute at each point.  I want to create a
> Voronoi/Dirichlet tesselation of these points coloring each tile by the z
> value.  I tried searching for a way to solve this and it was suggested to
> use the dirichlet() command to get the correct coloring.  However, my
> coloring is not correct.
>
> Any thoughts?

Does something like this do what you want?

require(deldir)
set.seed(42)
x <- runif(20)
y <- runif(20)
z <- sample(1:6,20,TRUE)
d <- deldir(x,y)
td <- tile.list(d)
plot(td,polycol=z,close=TRUE)

Note that the tiling assumes planar Euclidean distance, which might
create distortion in dealing with points on a sphere if the region in
which you observe the points is large.

     cheers,

         Rolf Turner

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Coloring Dirichlet Tiles

Felix Andrews
In reply to this post by baptiste auguie-5
On 5 September 2011 06:59, baptiste auguie
<[hidden email]> wrote:

> Hi,
>
> Try this,
>
> 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)))
>
> and also panel.voronoi in latticeExtra.
>
> Unfortunately I do not know of a solution that uses more efficient
> algorithms for computing the Dirichlet tessellation and extracting
> tiles than those relying on deldir. The Triangle package (r-forge)
> looks promising.


panel.voronoi() can use either deldir or tripack. tripack is non-free
but is much faster.

xyz <- data.frame(x = rnorm(1000), y = rnorm(1000), z = rnorm(1000))

library(latticeExtra)
system.time(print(tileplot(z ~ x * y, xyz))) ## deldir by default
#   user  system elapsed
#  3.636   0.004   3.651
system.time(print(tileplot(z ~ x * y, xyz, use.tripack = TRUE)))
#   user  system elapsed
#  1.176   0.000   1.359



>
> HTH,
>
> baptiste
>
>
> On 5 September 2011 06:26, awesolow <[hidden email]> wrote:
>> Hi,
>>
>> I have a set of x, y points (longitude/latitude) along with a z value
>> representing an attribute at each point.  I want to create a
>> Voronoi/Dirichlet tesselation of these points coloring each tile by the z
>> value.  I tried searching for a way to solve this and it was suggested to
>> use the dirichlet() command to get the correct coloring.  However, my
>> coloring is not correct.
>>
>> Any thoughts?
>>
>> Thanks in advance.
>>
>> --
>> View this message in context: http://r.789695.n4.nabble.com/Coloring-Dirichlet-Tiles-tp3789746p3789746.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



--
Felix Andrews / 安福立
http://www.neurofractal.org/felix/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.