Welcome to the PopGenHelpR vignette, please contact the authors if you have any questions about the package.You can also visit our Github for additional examples (https://kfarleigh.github.io/PopGenHelpR/)
# Load the package library(PopGenHelpR)
First, we will load the data. These data objects are examples of input that can be used in the functions Dif_stats_Map, Div_Stats_Map, Pairwise_heatmap, and Plot_ancestry.
data("Fst_dat") data("Het_dat") data("Q_dat") data("HornedLizard_Pop") data("HornedLizard_VCF")
Now we will use the data in the functions mentioned above. First, we will create structure-like plots and map pie charts of individual ancestry. You’ll notice that the individual map looks weird, the pie charts have a bunch of weird partitions. That’s because we have multiple individuals at the same location so the population map is probably a better choice. Instead of layering individuals on top of each other, the population map averages the ancestry of individuals in a population before mapping. See our Github for additional examples (https://kfarleigh.github.io/PopGenHelpR/), including ancestry pie charts on maps.
# First, we seperate the list elements into two seperate objects. The q-matrix (Qmat) and the locality information for each individual (Loc). <- Q_dat[] Qmat <- Q_dat[] Loc # Now we will generate both population and individual plots by setting plot.type to 'all'. If you wanted, you could only generate individual or population plots by setting plot.type to "individual" and "population", respectively. <- Plot_ancestry(anc.mat = Qmat, pops = Loc, K = 5, Test_all plot.type = 'all', col = c('#d73027', '#f46d43', '#e0f3f8', '#74add1', '#313695'), Lat_buffer = 1, Long_buffer = 1) #> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package, #> which was just loaded, will retire in October 2023. #> Please refer to R-spatial evolution reports for details, especially #> https://r-spatial.org/r/2023/05/15/evolution4.html. #> It may be desirable to make the sf package available; #> package maintainers should consider adding sf to Suggests:. #> The sp package is now running under evolution status 2 #> (status 2 uses the sf package in place of rgdal) $`Individual Ancestry Plot`Test_all
$`Population Ancestry Plot`Test_all
We will use the
Fst_dat object to visualize patterns of
differentiation between populations. First, we will generate a heat map
and then we will plot the realtionships on a map.
# Isolate our fst matrix and locality information <- Fst_dat[] Fst <- Fst_dat[] Loc # Plot the heatmap, the statistic argument is used to label the plot. <- Pairwise_heatmap(dat = Fst, statistic = 'FST') Fstat_hmap # Look at the plot Fstat_hmap
The heatmap is useful, but what about putting it on a map? First we will set a numeric neighbors argument to plot the Fst estimate between each population’s closest neighbor. Then we will specify relationships that we want to see using the population names.
# Closest Neighbor <- Dif_Stats_Map(dat = Fst, pops = Loc, neighbors = 1, Fst_map col = c('#FFFF00','#FFC000','#FFA500','#e31a1c','#800026'), Lat_buffer = 1, Long_buffer = 1) $`Differentiation Map`Fst_map
<- Dif_Stats_Map(dat = Fst, pops = Loc, neighbors = c('East_West', 'East_South', 'South_West'), Fst_map2 col = c('#FFFF00','#FFC000','#FFA500','#e31a1c','#800026'), Lat_buffer = 1, Long_buffer = 1) $`Differentiation Map`Fst_map2
Finally, we will map diversity values. We can color points based on diversity estimates and interpolated values to generate a raster to see how diversity changes across space. Here we only show the point method, but feel free to reach out if you have questions about the interpolation.
# Similar to our heat map, we use the statistic argument to label our figures and any output raster you create. <- Div_Stats_Map(dat = Het_dat, plot.type = 'point', Div_map statistic = "Heterozygosity", col = c('blue', 'orange', 'red'), Lat_buffer = 1, Long_buffer = 1, prefix = 'Test_het') $`Heterozygosity Map`Div_map
Thank you for your interest in our package, please reach out with any questions or things that should be included in future versions of the package.