View source: R/stemMappingExtension.R
stemMappingExtension | R Documentation |
The function cuts a circle stem map into a largest hexagon in circle and extends this hexagon to a target area and shape. This is a generic function.
stemMappingExtension(
objectID,
bearing,
distance,
plotRadius = 11.28,
targetArea = 1,
targetShape = "square",
randomRotate = FALSE,
randomSeed = as.numeric(NA)
)
objectID |
character, A object's ID, e.g., a tree's ID. |
bearing |
numeric, Azimuth of a object from the north. It should be between 0 to 360. |
distance |
numeric, Distance between a object and the centre of the circle. |
plotRadius |
numeric, Radius of the plot circle. If missing, |
targetArea |
numeric, Defines the area you may want to extend. The unit of this input is |
targetShape |
character, Defines the shape of the target area. It currently supports |
randomRotate |
logical, Defines whether need to random rotate the hexagon when merge into
a |
randomSeed |
numeric, Defines random seed for the random number generator.
This arguement is called when |
A table contains the x and y for all the objects in the extended area.
Yong Luo
## Not run:
## randomly generate some trees
library(data.table)
smallplottrees <- data.table(expand.grid(angle = seq(0, 360, 1),
distance = seq(0.1, 5.6, 0.1)))
smallplottrees[, tree_id := 1:nrow(smallplottrees)]
## extend it to 1 ha
treelist_smallplot <- stemMappingExtension(objectID = smallplottrees$tree_id,
bearing = smallplottrees$angle,
distance = smallplottrees$distance,
plotRadius = 5.64,
randomRotate = TRUE)
smallplottrees[tree_id %in% treelist_smallplot$objectID,
inHexigon := "Yes"]
smallplottrees[is.na(inHexigon),
inHexigon := "No"]
smallplottrees[,':='(x = sin(angle*pi/180)*distance,
y = cos(angle*pi/180)*distance)]
library(ggplot2)
trees_inplot <- ggplot(data = smallplottrees, aes(x = x, y = y))+
geom_point(aes(col = inHexigon))
trees_all <- ggplot(data = treelist_smallplot, aes(x = x, y = y))+
geom_point(aes(col = hexagonID))
bigplottrees <- data.table(tree_id = 1:20,
angle = runif(20, min = 0, max = 360),
distance = runif(20, min = 0, max = 11.28))
## extend it to 1 ha
treelist_bigplot <- stemMappingExtension(objectID = bigplottrees$tree_id,
bearing = bigplottrees$angle,
distance = bigplottrees$distance,
plotRadius = 11.28)
treelist_smallplot[, source := "smallplot"]
treelist_bigplot[, source := "bigplot"]
alltreelist <- rbind(treelist_bigplot, treelist_smallplot)
alltreeplot <- ggplot(data = alltreelist, aes(x, y))+
geom_point(aes(col = factor(source)))+
geom_point(data = alltreelist[hexagonID == 0,],
aes(x, y), col = "red")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.