# NOT RUN {
# }
# NOT RUN {
data(eco3)
# 1) "circle" method
con <- eco.weight(eco3[["XY"]], method = "circle", d1 = 0, d2 = 500)
#---- Different plot styles for the graph ----#
# simple
eco.plotWeight(con, type = "simple")
# igraph
eco.plotWeight(con, type = "igraph", group = eco3[["S"]]$structure)
# network (interactive)
## click in a node to see the label
eco.plotWeight(con, type = "network", bounded = TRUE, group = eco3[["S"]]$structure)
# edgebundle (interactive)
## in the following plot, the assignment a group factor,
## generates clustered nodes.
## hover over the nodes to see the individual connections
eco.plotWeight(con, type = "edgebundle", fontSize=8, group = eco3[["S"]]$structure)
# 2) "knearest" method
con <- eco.weight(eco3[["XY"]], method = "knearest", k = 10)
eco.plotWeight(con)
eco.plotWeight(con, type = "network", bounded = TRUE, group = eco3[["S"]]$structure)
# 3) "inverse" method
## scale dependent. In the example, the original coordinates (in km) are converted into m
con <- eco.weight(eco3[["XY"]]/1000, method = "inverse", max.sd = TRUE, p = 0.1)
con
eco.plotWeight(con)
# 4) "circle.inverse" method
con <- eco.weight(eco3[["XY"]], method = "circle.inverse", d2 = 1000)
con
eco.plotWeight(con)
# 5) "exponential" method
## scale dependent. In the example, the original coordinates (in km) are converted into m
con <- eco.weight(eco3[["XY"]]/1000, method = "exponential", max.sd = TRUE, alpha = 0.1)
eco.plotWeight(con)
# 6) "circle.exponential" method
con <- eco.weight(eco3[["XY"]], method = "circle.exponential", d2 = 2000)
con
eco.plotWeight(con)
# 7) CUSTOM WEIGHT MATRIX
## An eco.weight object can be created with a custom W matrix. In this case,
## the rows and the columns of W (weight matrix) must have names,
## that must coincide (also in order) with the name of the XY (position) matrix.
require(igraph)
## this example generates a network with the package igraph
tr <- make_tree(40, children = 3, mode = "undirected")
plot(tr, vertex.size = 10, vertex.label = NA)
## conversion from igraph to weight matrix
weights <- as.matrix(as_adj(tr))
## weight matrix requires named rows and columns
myNames <- 1:nrow(weights)
rownames(weights) <- colnames(weights) <- myNames
## extract coordinates from the igraph object
coord <- layout.auto(tr)
rownames(coord) <- myNames
plot(layout.auto(tr))
## custom weight object
customw <- eco.weight(XY = coord, W = weights)
## simple plot of the object
eco.plotWeight(customw, type = "simple")
## create a vector with groups to have coloured plots
myColors <- c(rep(1,13), rep(2, 9), rep(3, 9), rep(4, 9))
eco.plotWeight(customw, type = "igraph",group = myColors)
## in the following plot, the argument bounded is set to FALSE,
## but if you have many groups, it probably should be set to TRUE.
# click in a node to see the label
eco.plotWeight(customw,type = "network", bounded = FALSE, group = myColors)
## in the following plot, the assignment a group factor,
# generates clustered nodes.
# hover over the name of the nodes to see the individual connections
eco.plotWeight(customw, type = "edgebundle", group = myColors)
#### CONVERSION FROM LISTW OBJECTS #####
require(adegenet)
# Delaunay triangulation
temp <-chooseCN(eco3[["XY"]], type = 1, result.type = "listw", plot.nb = FALSE)
con <- eco.listw2ew(temp)
eco.plotWeight(con, "network", bounded = TRUE, group = eco3[["S"]]$structure)
#-----------------------
# ACCESSORS USE EXAMPLE
#-----------------------
# the slots are accessed with the generic format
# (ecoslot. + name of the slot + name of the object).
# See help("EcoGenetics accessors")
ecoslot.METHOD(con) # slot METHOD
ecoslot.PAR(con) # slot PAR
ecoslot.PAR.VAL(con) # slot PAR.VAL
# }
# NOT RUN {
# }
Run the code above in your browser using DataCamp Workspace