#' geodata
#'
#' A multi-object dataset contain many of the layers you
#' may want to plot for switchgrass diversity
#'
#' @format A set of 11 objects in unprojected lat/lon
#' coordinates. All datasets are either raster (bio.layers)
#' or SpatialLines/PolygonDataframes and have been cropped
#' to the extent of the diversity points.
#' \describe{
#' \item{bio.layers}{RasterBrick with the 19 bioclim laaaters at
#' a resolution of 2.5.}
#' \item{extent}{The latitude / longitude extent of the dataset}
#' \item{l.states}{SpatialPolygonsDataFrame with bounds of
#' USA, MEX and CAN}
#' \item{o.states}{SpatialPolygonsDataFrame with bounds of
#' all non-USA admin}
#' \item{us.states}{SpatialPolygonsDataFrame with bounds of
#' USA states}
#' \item{rivers}{SpatialLinesDataFrame with paths of rivers}
#' \item{countries}{SpatialLinesDataFrame with boundaries of
#' countries}
#' \item{coasts}{SpatialLinesDataFrame with paths of coasts}
#' \item{great.lakes}{SpatialPolygonsDataFrame with bounds of
#' great lakes}
#' \item{lakes}{SpatialPolygonsDataFrame with bounds of lakes}
#' \item{land}{SpatialPolygonsDataFrame with bounds of land}
#' }
#' @source
#' \dontrun{
#' # 1. get and crop bioclim data
#' extent <- c(
#' -111, -65, # longitude
#' 22, 51) # latitude
#'
#' bio.layers <- raster::getData(
#' name = 'worldclim',
#' var = 'bio',
#' res = 2.5)
#'
#'
#' # 2. get and crop other geographical data
#' devtools::install_github("jtlovell/spatialMapData")
#' library(spatialMapData)
#'
#' # 2.1 states
#' data(
#' ne_10m_admin_1_states_provinces.shp,
#' package = "spatialMapData")
#' states <- crop(
#' ne_10m_admin_1_states_provinces.shp,
#' extent)
#' us.states1 <- subset(
#' states,
#' grepl("USA", adm1_code))
#' o.states <- subset(
#' states,
#' !grepl("USA", adm1_code))
#' l.states <- subset(
#' states,
#' grepl("MEX|USA|CAN", adm1_code))
#'
#' # 2.2 rivers
#' data(
#' ne_10m_rivers_lake_centerlines.shp,
#' package = "spatialMapData")
#' rivers <- crop(
#' ne_10m_rivers_lake_centerlines.shp,
#' extent)
#'
#' # 2.3 countries
#' data(
#' ne_10m_admin_0_boundary_lines_land.shp,
#' package = "spatialMapData")
#' countries <- crop(
#' ne_10m_admin_0_boundary_lines_land.shp,
#' extent)
#'
#' # 2.4 coasts
#' data(
#' ne_10m_coastline.shp,
#' package = "spatialMapData")
#' coasts <- crop(
#' ne_10m_coastline.shp,
#' extent)
#'
#' # 2.5 lakes
#' data(
#' ne_10m_lakes.shp,
#' package = "spatialMapData")
#' lakes <- crop(
#' ne_10m_lakes.shp,
#' extent)
#' great.lakes <- subset(
#' lakes,
#' lakes[[5]] == "Great Lakes")
#'
#' # 2.6 land
#' data(
#' ne_10m_land.shp,
#' package = "spatialMapData")
#' land <- crop(
#' ne_10m_land.shp,
#' extent)
#'
#' geodata <- list(
#' land = land,
#' lakes = lakes,
#' great.lakes = great.lakes,
#' coasts = coasts,
#' countries = countries,
#' rivers = rivers,
#' states = states,
#' o.states = o.states,
#' l.states = l.states,
#' extent = extent,
#' bio.layers = bio.layers)
#' save(
#' geodata,
#' file = "./data/geodata.rda")
#' #' }
#'
"geodata"
#' k5.structure
#'
#' A data.table with k = 5 membership by library
#'
#' @format A data.table with the following columns
#' \describe{
#' \item{bio.layers}{RasterBrick with the 19 bioclim laaaters at
#' a resolution of 2.5.}
#' \item{extent}{The latitude / longitude extent of the dataset}
#' \item{l.states}{SpatialPolygonsDataFrame with bounds of
#' USA, MEX and CAN}
#' \item{o.states}{SpatialPolygonsDataFrame with bounds of
#' all non-USA admin}
#' \item{us.states}{SpatialPolygonsDataFrame with bounds of
#' USA states}
#' \item{rivers}{SpatialLinesDataFrame with paths of rivers}
#' \item{countries}{SpatialLinesDataFrame with boundaries of
#' countries}
#' \item{coasts}{SpatialLinesDataFrame with paths of coasts}
#' \item{great.lakes}{SpatialPolygonsDataFrame with bounds of
#' great lakes}
#' \item{lakes}{SpatialPolygonsDataFrame with bounds of lakes}
#' \item{land}{SpatialPolygonsDataFrame with bounds of land}
#' }
#' @source
#' \dontrun{
#' field.metadata <- data.table(openxlsx::read.xlsx("~/Google Drive/Switchgrass-Genome/Switchgrass_V5_manuscript/raw_tables/GWAS_2019_Master Plant List.xlsx"))
#' plant.metadata <- fread("~/Google Drive/Switchgrass-Genome/Switchgrass_V5_manuscript/raw_tables/PVDIV_Master Metadata File_9-3-2019.csv")
#' plant.metadata <- plant.metadata[,c("PLANT_ID","ECOTYPE_SNP_CHLR","LATITUDE","LONGITUDE","COLLECTION_TYPE")]
#' setnames(plant.metadata, c("id","cp.eco","lat","lon","ctype"))
#' k5.assign.prob <- fread("~/Google Drive/Switchgrass-Genome/Switchgrass_V5_manuscript/raw_tables/Pvirgatum_4x_784g.5.meanQ",
#' col.names = paste0("q",1:5))
#' tmp <- fread("~/Google Drive/Switchgrass-Genome/Switchgrass_V5_manuscript/raw_tables/Pvirgatum_4x_784g.5.meanQ.sample_order.txt",
#' header = F, col.names = "id")
#' coln <- paste0("q",1:5)
#' setnames(k5.assign.prob, coln, c("TX","GC","MW","S.EC","N.EC"))
#' coln <- c("TX","GC","MW","S.EC","N.EC")
#' k5.assign.prob[,best := apply(.SD, 1, function(x) coln[which.max(x)]),
#' .SDcols = coln]
#' k5.assign.prob$qi.best <- sapply(1:nrow(k5.assign.prob), function(i){
#' x <- unlist(k5.assign.prob[i,coln,with = F])
#' y <- k5.assign.prob$best[i]
#' return(x[y])
#' })
#' k5.assign.prob <- data.table(tmp, k5.assign.prob)
#' plant.metadata.k5 <- merge(plant.metadata, k5.assign.prob, by = "id")
#'
#' d4 <- data.table(plant.metadata.k5)
#' subpop.names <- c("TX", "GC", "S.EC","N.EC", "MW")
#' d4[,subpop := factor(best, levels = subpop.names)]
#' d4[,adm.rat := apply(.SD, 1, function(x) max(x[-which.max(x)]) / max(x)),
#' .SDcols = subpop.names]
#' d4[,is.adm := adm.rat > .01]
#' d4[,qi2best := apply(.SD,1,function(x) subpop.names[order(-x)][2]),
#' .SDcols = subpop.names]
#' d4[,n3.admx := apply(.SD,1,function(x) sum(x > .2) > 2),
#' .SDcols = subpop.names]
#' plant.metadata.k5[,structure.order := as.numeric(factor(id, levels = d4$id))]
#'
#' d4[,subpop2best := factor(qi2best, levels = subpop.names)]
#' setkey(d4, n3.admx, subpop, subpop2best, adm.rat)
#'
#' subpop.cols <- c("red2","salmon","cornflowerblue","blue2","orange")
#' names(subpop.cols) <- subpop.names
#' plant.metadata.k5[,best.col := subpop.cols[best]]
#' save(
#' plant.metadata.k5,
#' file = "./data/plant.metadata.k5.rda")
#' }
#'
"plant.metadata.k5"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.