This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The genotype matrix has individuals in rows and mutations #in columns, with a 0,1, or 2 entered for the number of #alternate alleles in the diploid | |
# Let’s create a matrix with 5 individuals, 10 SNPS, and some missing data: | |
set.seed(345) | |
GEN = matrix(sample(0:2, 50, replace=TRUE), nrow=5, ncol=10) | |
GEN[5,1] <- NA | |
GEN | |
# Function to calculate the allele frequency of a column | |
af <- function(i, gen){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ggtheme <- theme_bw() + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), panel.border=element_blank(), axis.line = element_line(colour="grey30"), axis.title = element_text(colour="grey20"), axis.text = (element_text(colour="grey30")), legend.title = element_text(colour="grey20"), legend.text = element_text(colour="grey30")) | |
to use it, just use: | |
ggplot(data) + geom_point(aes(x=x, y=y)) + ggtheme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
par(xpd=NA, oma=c(4,0,0,0), mar=c(2,4,0,0),mfrow=c(1,1)) | |
plot(1,1, xlim=c(-1,1), ylim=c(0,1)) | |
# This is for a plot with x-axis from -1 to 1 and y axis from 0 to 1. It plots a legend in the bottom margin | |
legend(-1,-0.25, legend=c("high sal.", "low sal."), bty="n", adj=0, fill=c("grey", NA), horiz=TRUE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
packages_needed <- c("raster", "FNN", "RColorBrewer", "colorRamps", "adehabitatLT", | |
"data.table", "tidyverse", "fields", "ggplot2", "hexbin", | |
"rgdal", "tmap", "gstat", "sp", "maptools", "sf", "fasterize", | |
"fansi", "raster", "tmap", "gstat", "ContourFunctions","ash" | |
) | |
for (i in 1:length(packages_needed)){ | |
if(!(packages_needed[i] %in% installed.packages())){install.packages(packages_needed[i])} | |
} |