Question

I'm trying to produce voronoi diagrams with R. The plotting of the diagrams itself is working fine, but I have a problem with labelling the different tiles of my plots.

The code I'm using is as follows:

data <- read.csv("data.csv", sep=",")
x <- data$column1
y <- data$column2
voro <- deldir(x,y,rw=c(0,1,0,1))
list <- tile.list(voro)
color <- heat.colors(6)
plot(list,polycol=color,close=TRUE)
plot(voro,number=TRUE,add=TRUE,wlines=c('tess'))

Is it possible to swap the numbers for custom labels before plotting the diagram?

Was it helpful?

Solution

You can use text to add the labels (you already know the coordinates, x and y).

library(deldir)
# Sample data
x    <- c(2.3,3.0,7.0,1.0,3.0,8.0)
y    <- c(2.3,3.0,2.0,5.0,8.0,9.0)
voro <- deldir(x,y,list(ndx=2,ndy=2),c(0,10,0,10))

# Plot
plot( tile.list(voro), polycol = heat.colors(6), close=TRUE )
plot( voro, add = TRUE, wlines = 'tess' )
text( x, y, labels = LETTERS[1:length(x)], adj = c(0,0) )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top