View source: R/createRealizations.R
createRealizations | R Documentation |
This function creates multiple realizations of patches of the variable of interest within the grid of locations created with createPopulation
.
createRealizations( x_start, x_end, y_start, y_end, buffer, n.networks, n.realizations, SpeciesInfo, start.seed, variables, yvar )
x_start |
The most western coordinate of the grid |
x_end |
The most eastern coordinate of the grid. |
y_start |
The most southern coordinate of the grid. |
y_end |
The most northern coordinate of the grid. |
buffer |
The distance from the edge of the grid from which initial samples should not be taken. |
n.networks |
The number of networks to be placed in the realization. |
n.realizations |
The number of realizations to create per |
SpeciesInfo |
A dataframe containing, at a minimum, x and y coordinates and the variable of interest. Should only include plots that have the species of interest. |
start.seed |
The initial number used in |
variables |
Dataframe column names that are included in the final patch realizations. These columns are given a value of "0" if the species is not present or NA. |
yvar |
The variable of interest that determines how units will be assigned if during the randomization and rotation two units overlap. Must be a variable listed within the argument |
saubyadaptiveACSampling
library(magrittr) library(dplyr) library(ggplot2) # EXAMPLE 1 # how large does the buffer need to be when generating realizations? (so # that network units are not truncated by the dimensions of the realization # grid) data(PlotSurveys_season1) PlotSurveys_season1 %>% as.data.frame %>% summarise( max_x_buffer = max(abs(Rel_x)), max_y_buffer = max(abs(Rel_y)) ) # realization info x_start = 1 x_end = 30 y_start = 1 y_end = 30 n.networks = c(5, 15, 10, 20, 30, 40) n.realizations = 1 SpeciesInfo = PlotSurveys_season1 variables = c("Stricta", "Pusilla", "Cactus") start.seed=1 buffer=5 # create realizations CactusRealizations = createRealizations( x_start, x_end, y_start, y_end, buffer, n.networks, n.realizations, SpeciesInfo, start.seed, variables, yvar = "Cactus" ) # plot realizations p <- ggplot(CactusRealizations, aes(x, y, colour=NetworkID, label=NetworkID)) p + annotate("rect", xmin=x_start, xmax=x_end, ymin=y_start, ymax=y_end, alpha=0, colour="grey") + geom_point(aes(size=factor(Cactus))) + facet_wrap(~n.networks) + scale_colour_gradientn(colours = rainbow(7)) + geom_text(aes(label=NetworkID), hjust=0, vjust=0) p <- ggplot(CactusRealizations %>% filter(m>1), aes(x, y, colour=NetworkID, label=NetworkID)) p + annotate("rect", xmin=x_start, xmax=x_end, ymin=y_start, ymax=y_end, alpha=0, colour="grey") + geom_point(aes(size=factor(Cactus))) + facet_wrap(~n.networks) + scale_colour_gradientn(colours = rainbow(7)) + geom_text(aes(label=NetworkID), hjust=0, vjust=0) # EXAMPLE 2 # realization info x_start = 1 x_end = 20 y_start = 1 y_end = 20 n.networks = c(1,2,3) n.realizations = 1 SpeciesInfo = Thompson1990Fig1Pop %>% filter(m > 1) %>% createNetworks variables = "y_value" buffer=5 start.seed=1 # create realizations Thompson.realizations = createRealizations(x_start, x_end, y_start, y_end, buffer, n.networks, n.realizations, SpeciesInfo, start.seed, variables, yvar="y_value") # plot realizations p <- ggplot(Thompson.realizations, aes(x, y, colour=NetworkID, label=NetworkID)) p + annotate("rect", xmin=x_start, xmax=x_end, ymin=y_start, ymax=y_end, alpha=0, colour="grey") + geom_point(aes(size=factor(y_value))) + facet_wrap(~n.networks) + scale_colour_gradientn(colours = rainbow(7)) + geom_text(aes(label=NetworkID), hjust=0, vjust=0) p <- ggplot(Thompson.realizations %>% filter(m > 1), aes(x, y, colour=NetworkID, label=NetworkID)) p + annotate("rect", xmin=x_start, xmax=x_end, ymin=y_start, ymax=y_end, alpha=0, colour="grey") + geom_point(aes(size=factor(y_value))) + facet_wrap(~n.networks) + scale_colour_gradientn(colours = rainbow(7)) + geom_text(aes(label=NetworkID), hjust=0, vjust=0)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.