# Longleaf pines data
plot(longleaf)
<testonly>longleaf <- longleaf[seq(1,longleaf$n,by=10)]</testonly>
# adult trees defined to have diameter at least 30 cm
adult <- (longleaf$marks >= 30)
longadult <- longleaf[adult]
plot(longadult)
# note that the marks are still retained.
# Use unmark(longadult) to remove the marks
# New Zealand trees data
plot(nztrees) # plot shows a line of trees at the far right
abline(v=148, lty=2) # cut along this line
nzw <- owin(c(0,148),c(0,95)) # the subwindow
# trim dataset to this subwindow
nzsub <- nztrees[nzw]
plot(nzsub)
# Redwood data
plot(redwood)
# Random thinning: delete 60\% of data
retain <- (runif(redwood$n) < 0.4)
thinred <- redwood[retain]
plot(thinred)
# Scramble 60\% of data
modif <- (runif(redwood$n) < 0.6)
scramble <- function(x) { runifpoint(x$n, x$window) }
redwood[modif] <- scramble(redwood[modif])
# Lansing woods data - multitype points
<testonly>lansing <- lansing[seq(1, lansing$n, length=100)]</testonly>
# Hickory trees
hicks <- split(lansing)$hickory
# Trees in subwindow
win <- owin(c(0.3, 0.6),c(0.2, 0.5))
lsub <- lansing[win]
# Scramble the locations of trees in subwindow, retaining their marks
lansing[win] <- scramble(lsub) %mark% (lsub$marks)
# Extract oaks only
oaknames <- c("redoak", "whiteoak", "blackoak")
oak <- lansing[marks(lansing) %in% oaknames, drop=TRUE]
oak <- subset(lansing, marks %in% oaknames, drop=TRUE)
# To clip or not to clip
X <- runifpoint(25, letterR)
B <- owin(c(2.2, 3.9), c(2, 3.5))
opa <- par(mfrow=c(1,2))
plot(X, main="X[B]")
plot(X[B], border="red", cols="red", add=TRUE, show.all=TRUE, main="")
plot(X, main="X[B, clip=TRUE]")
plot(B, add=TRUE, lty=2)
plot(X[B, clip=TRUE], border="blue", cols="blue", add=TRUE,
show.all=TRUE, main="")
par(opa)
Run the code above in your browser using DataLab