# NOT RUN {
# }
# NOT RUN {
data(eco.test)
require(ggplot2)
##########################
# Moran's I correlogram
##########################
## single test with phenotypic traits
moran <- eco.correlog(Z=eco[["P"]][,1], XY = eco[["XY"]],
method = "I", smax=10, size=1000)
# interactive plot via plotly
eco.plotCorrelog(moran)
# standard plot via ggplot2
eco.plotCorrelog(moran, interactivePlot = FALSE)
#-------------------------------------------------------
## A directional approach based in bearing correlograms
#-------------------------------------------------------
moran_b <- eco.correlog(Z=eco[["P"]][,1], XY = eco[["XY"]],
method = "I", smax = 10, size = 1000, angle = seq(0, 175, 5))
# use eco.plotCorrelogB for this object
eco.plotCorrelogB(moran_b)
# plot for the first distance class,
use a number between 1 and the number of classes to select the corresponding class
eco.plotCorrelogB(moran_b, var = 1)
#-----------------------------
## Multivariable correlograms
#-----------------------------
## multiple tests with phenotypic traits
moran2 <- eco.correlog(Z=eco[["P"]], XY = eco[["XY"]],
method = "I", smax=10, size=1000)
eco.plotCorrelog(moran2, var ="P2") ## single plots
eco.plotCorrelog(moran2, var ="P3") ## single plots
## Multivariable interactive plot with mean correlogram
## and jackknifed confidence intervals.
graf <- eco.plotCorrelog(moran2, meanplot = TRUE)
# Only mean
graf$mean.correlog
# Mean and variables
graf$multi.correlog
# Information
- correlogram data for individual variables
- manhattan distance matrix
- mean correlogram data
- method used for analysis
- names and numbers (column in data frame) of significant variables
graf$data
# plot only alleles
graf <- eco.plotCorrelog(moran2, meanplot = FALSE)
graf
# Both plots can also be constructed using ggplot2
gg_graf <- eco.plotCorrelog(moran2, meanplot = TRUE, interactivePlot = FALSE)
gg_graf[[1]]
gg_graf[[2]]
gg_graf <- eco.plotCorrelog(moran2, meanplot = FALSE, interactivePlot = FALSE)
gg_graf
# standard ggplot2 correlograms support the use of ggplot2 syntax
require(ggplot2)
moranplot <- eco.plotCorrelog(moran2, var ="P3", interactivePlot = FALSE)
moranplot <- moranplot + theme_bw() + theme(legend.position="none")
moranplot
moranplot2 <- gg_graf[[2]] + theme_bw() + theme(legend.position="none")
moranplot2
#-----------------------
Analyzing genetic data
#-----------------------
# single test with genotypic traits
# eco[["A"]] is a matrix with the genetic data of "eco"
# as frequencies for each allele in each individual. Each allele
# can be analyzed as single traits.
head(eco[["A"]]) # head of the matrix
# analyzing allele 1
moran <- eco.correlog(Z=[["A"]][,1], XY = eco[["XY"]], method = "I",
smax=10, size=1000)
eco.plotCorrelog(moran)
# multiple tests with genotypic traits.
# nsim is set to 10 only for speed in the example
moran2 <- eco.correlog(Z = eco[["A"]], XY = eco[["XY"]],
method = "I",smax=10, size=1000, nsim=99)
## multiple plot with mean
## correlogram and jackknifed
## confidence intervals.
graf <- eco.plotCorrelog(moran2, meanplot = TRUE)
## the same example, but with nsim = 99.
moran3 <- eco.correlog(Z = eco[["A"]], XY = eco[["XY"]], method = "I",
smax=10, size=1000, nsim=99)
## plot for alleles with at least one significant value after
## Bonferroni-Holm sequential P correction
## (set adjust "none" for no family-wise
## P correction in "eco.correlog")
eco.plotCorrelog(moran3, meanplot = TRUE, significant.M = TRUE)
#-----------------------
# ACCESSORS USE EXAMPLE
#-----------------------
# the slots are accesed with the generic format
# (ecoslot. + name of the slot + name of the object).
# See help("EcoGenetics accessors")
ecoslot.OUT(moran) # slot OUT
ecoslot.BREAKS(moran) # slot BREAKS
#---------------------------------------------------------------------------#
##########################
# Geary's C correlogram
##########################
geary <- eco.correlog(Z = eco[["P"]][,1], XY = eco[["XY"]], method = "C",
smax=10, size=1000)
# Interactive plot
eco.plotCorrelog(geary)
# ggplot2 plot
eco.plotCorrelog(geary, interactivePlot = FALSE)
#---------------------------------------------------------------------------#
##########################
# Bivariate Moran's Ixy
##########################
cross <- eco.correlog(Z=eco[["P"]][,1], XY = eco[["XY"]], Y = eco[["P"]][, 1],
method = "CC", int= 2, smax=15)
# Interactive plot
eco.plotCorrelog(cross)
# ggplot2 plot
eco.plotCorrelog(cross, interactivePlot = FALSE)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab