Skip to content

Commit

Permalink
updated with rayshader plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
bomeara committed Nov 11, 2022
1 parent 893e682 commit fbf66c0
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 9 deletions.
7 changes: 6 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,27 @@ Depends:
Imports:
CoordinateCleaner,
datelife,
elevatr,
geiger,
jsonlite,
magrittr,
paleotree,
phangorn,
plyr,
raster,
rayshader,
rentrez,
rfishbase,
rgbif,
rmarkdown,
rotl,
rvest,
sf,
sp,
speciesgeocodeR,
spocc,
taxize,
tidyverse,
utils
Suggests:
testthat (>= 2.1.0)
Expand All @@ -41,4 +46,4 @@ Remotes:
phylotastic/datelife
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.2.1
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export(contrasts_correlations)
export(convert_continuous_to_discrete)
export(descendant_species)
export(eol_data)
export(eol_traits)
export(eol_traits2)
export(fishbase_genus_query)
export(fishbase_species_query)
export(gbif_species_query)
Expand All @@ -24,6 +26,7 @@ export(locality_add_habitat_biome)
export(locality_clean)
export(match_data)
export(pbdb_taxon_query)
export(plot_gis)
export(render_chapter2)
export(run_biogeobears)
export(run_chapter2)
Expand Down
48 changes: 48 additions & 0 deletions R/dataFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,53 @@ locality_clean <- function(locations) {
return(CoordinateCleaner::clean_coordinates(locations, lon="longitude", lat="latitude", species=NULL, tests=c( "centroids", "equal", "gbif", "institutions","zeros"), value="clean"))
}

#' Plot a map of points
#' @param gbif_points Data.frame containing points (latitude and longitude, perhaps other data as columns)
#' @return A ggplot2 map
#'
#' Note that we will need to set zoom automatically, also add points, also make the ocean full of water.
#' @examples
#' gis_points <- spocc_taxon_query("Tyto", limit=100, sources="gbif")
#' plot_gis(gbif_points)
#' @export
plot_gis <- function(gbif_points) {
min_lat <- min(gbif_points$latitude)
max_lat <- max(gbif_points$latitude)
min_lon <- min(gbif_points$longitude)
max_lon <- max(gbif_points$longitude)

med_bbox <- sf::st_bbox(c(xmin = min_lon, xmax = max_lon, ymin = min_lat, ymax = max_lat),
crs = 4326)

med_bbox_df <- data.frame(x = c(min_lon, max_lon),
y = c(min_lat, max_lat))


extent_zoomed <- raster::extent(med_bbox)
prj_dd <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

elev_med <- elevatr::get_elev_raster(med_bbox_df, prj = prj_dd, z = 3, clip = "bbox")
elev_med_mat <- rayshader::raster_to_matrix(elev_med)

base_map <- elev_med_mat %>%
height_shade() %>%
add_overlay(
sphere_shade(elev_med_mat,
texture = rayshader::create_texture(
lightcolor = "#b8ff78",
shadowcolor = "#193600",
leftcolor = "#80d453",
rightcolor = "#80d453",
centercolor = "#568a27"),
sunangle = 0,
colorintensity = 5)
)

base_map %>% plot_map()
return(base_map)
}


#' Use azizka/speciesgeocodeR/ and WWF data to encode locations for habitat and biome
#'
#' Uses info from http://omap.africanmarineatlas.org/BIOSPHERE/data/note_areas_sp/Ecoregions_Ecosystems/WWF_Ecoregions/WWFecoregions.htm to convert codes to more readable text
Expand Down Expand Up @@ -352,6 +399,7 @@ get_datelife_biggest <- function(taxon) {
clade.name<- rotl::tnrs_match_names(taxon)$unique_name[1]
datelife_biggest <- NULL
try(datelife_biggest <- datelife::datelife_search(input=clade.name, get_spp_from_taxon=TRUE, summary_format="phylo_biggest"))

return(datelife_biggest)
}

Expand Down
5 changes: 2 additions & 3 deletions R/eoldata.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ eol_data <- function(species) {
#'
#' @param eol_df A data frame produced by the function eol_data
#' @return A data frame of one row with columns: behavior circadian rhythm, developmental mode, visual system, and wing morphology
#' @export
#'
#' This works for a single species but not for the multi-species data frame produced by get_eol
#' @export
eol_traits <- function(eol_df){
df2 <- subset(eol_df, select = c(species, trait, value))
#remove duplicate rows
Expand All @@ -75,9 +75,8 @@ eol_traits <- function(eol_df){
#'
#' @param eol_df A data frame produced by the function eol_data
#' @return A data frame of one row with columns: behavior circadian rhythm, developmental mode, visual system, and wing morphology
#' @export
#'
#' This one works for the full data frame produced by get_eol - maybe rework it with pipes?
#' @export
eol_traits2 <- function(eol_df){
#select the columns we want
df2 <- subset(eol_df, select = c(species, trait, value))
Expand Down
8 changes: 5 additions & 3 deletions R/runanalysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ run_chapter2 <- function(taxon) {
genbank_count <- get_genbank_count(taxon)
otol <- get_otol(taxon)
eol <- get_eol(taxon)
eol_tbl <- eol_traits2(eol)
location_realm_biome <- get_location_realm_biome(taxon)
return(list(wikipedia_summary=wikipedia_summary, datelife_biggest=datelife_biggest, pubmed=pubmed, genbank_count_by_gene=genbank_count_by_gene, genbank_count=genbank_count , otol=otol, location_realm_biome=location_realm_biome, eol=eol, eol_tbl=eol_tbl))
#eol_tbl <- eol_traits2(eol)
# location_realm_biome <- get_location_realm_biome(taxon)
#return(list(wikipedia_summary=wikipedia_summary, datelife_biggest=datelife_biggest, pubmed=pubmed, genbank_count_by_gene=genbank_count_by_gene, genbank_count=genbank_count , otol=otol, location_realm_biome=location_realm_biome, eol=eol, eol_tbl=eol_tbl))
return(list(wikipedia_summary=wikipedia_summary, datelife_biggest=datelife_biggest, pubmed=pubmed, genbank_count_by_gene=genbank_count_by_gene, genbank_count=genbank_count , otol=otol, eol=eol))

}

#' Create a file of results
Expand Down
4 changes: 2 additions & 2 deletions inst/rmd/summary.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if(nrow(pubmed.df)>0) {

Here is information about realms (biogeographic regions) by species; frequency of record in each realm.

```{r, echo=FALSE}
```{r, echo=FALSE, eval=FALSE}
realm <- all_results$location_realm_biome$realm
for (i in sequence(nrow(realm))) {
realm[i,] <- realm[i,]/sum(realm[i,], na.rm=TRUE)
Expand All @@ -75,7 +75,7 @@ pander::pander(data.frame(realm))

Here is information about biomes by species; frequency of records in each biome.

```{r, echo=FALSE}
```{r, echo=FALSE, eval=FALSE}
biome <- all_results$location_realm_biome$biome
for (i in sequence(nrow(biome))) {
biome[i,] <- biome[i,]/sum(biome[i,], na.rm=TRUE)
Expand Down
19 changes: 19 additions & 0 deletions man/eol_traits.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/eol_traits2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions man/get_location_realm_biome.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions man/plot_gis.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fbf66c0

Please sign in to comment.