x <- c(2.3,3.0,7.0,1.0,3.0,8.0) + 0.5
y <- c(2.3,3.0,2.0,5.0,8.0,9.0) + 0.5
x <- c(x,1,10,10,1)
y <- c(y,1,1,10,10)
dxy <- deldir(x,y,rw=c(0,11,0,11))
plot(dxy)
# Plots the tessellation, but does not save the results:
deldir(x,y,rw=c(0,11,0,11),plot=TRUE,
wl="tess",cmpnt_col=c(1,1,2,3,4),labelPts=TRUE)
# Plots the triangulation, but not the tessellation or the points,
# and saves the returned structure:
dxy <- deldir(x,y,rw=c(0,11,0,11),plot=TRUE,wl="triang",wp="none")
# Plot everything:
plot(dxy,cmpnt_col=c("orange","green","red","blue","black"),cmpnt_lty=1,
labelPts=TRUE,lex=1.5,pch=c(19,9),showrect=TRUE,axes=TRUE)
# Complicated example from He Huang:
# "Linguistic distances".
vldm <- c(308.298557,592.555483,284.256926,141.421356,449.719913,
733.976839,591.141269,282.842712,1.414214,732.562625)
ldm <- matrix(nrow=5,ncol=5)
ldm[row(ldm) > col(ldm)] <- vldm
ldm[row(ldm) <= col(ldm)] <- 0
ldm <- (ldm + t(ldm))/2
rownames(ldm) <- LETTERS[1:5]
colnames(ldm) <- LETTERS[1:5]
# Data to be triangulated.
id <- c("A","B","C","D","E")
x <- c(0.5,1,1,1.5,2)
y <- c(5.5,3,7,6.5,5)
dat_Huang <- data.frame(id = id, x = x, y = y)
# Form the triangulation/tessellation.
dH <- deldir(dat_Huang)
# Plot the triangulation with line widths proportional
# to "linguistic distances".
all_col <- rainbow(100)
i <- pmax(1,round(100*vldm/max(vldm)))
use_col <- all_col[i]
ind <- as.matrix(dH$delsgs[,c("ind1","ind2")])
lwv <- ldm[ind]
lwv <- 10*lwv/max(lwv)
plot(dH,wlines="triang",col=use_col,showpoints=FALSE,
lw=lwv,asp=NA)
with(dH,text(x,y,id,cex=1.5))
Run the code above in your browser using DataLab