Skip to content

Commit

Permalink
website
Browse files Browse the repository at this point in the history
  • Loading branch information
dlizcano committed Mar 25, 2024
1 parent d44d03c commit fa142f7
Show file tree
Hide file tree
Showing 16 changed files with 259 additions and 16 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^_pkgdown\.yml$
^docs$
^pkgdown$
^codecov\.yml$
39 changes: 25 additions & 14 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,36 @@ Package: mammalcol
Title: Access to the List of Mammals Species of Colombia
Version: 0.1.0
Authors@R:
person("Diego J.", "Lizcano", ,
"[email protected]", role = c("aut", "cre"),
person("Diego J.", "Lizcano", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9648-0576"))
Maintainer: Diego J. Lizcano <[email protected]>
Description: Allows access to the data found in the species list featured in the renowned "Ramírez-Chaves, et al. 2021. Checklist of the Mammals (Mammalia) of Colombia”. Mammalogy Notes 7(2),253. <https://doi.org/10.47603/mano.v7n2.253>. This publication stands as one of Colombia's most comprehensive reviews of mammal diversity. The dataset incorporates detailed species accounts and has been meticulously structured for effortless utilization within the R environment.
Description: Allows access to the data found in the species list featured
in the renowned "Ramírez-Chaves, et al. 2021. Checklist of the Mammals
(Mammalia) of Colombia”. Mammalogy Notes 7(2),253.
<https://doi.org/10.47603/mano.v7n2.253>. This publication stands as
one of Colombia's most comprehensive reviews of mammal diversity. The
dataset incorporates detailed species accounts and has been
meticulously structured for effortless utilization within the R
environment.
License: MIT + file LICENSE
Imports:
dplyr,
ggplot2,
sf
Suggests:
testthat (>= 3.0.0),
dplyr
Config/testthat/edition: 3
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
URL: https://github.com/dlizcano/mamalcol, https://dlizcano.github.io/mammalcol/
URL: https://github.com/dlizcano/mamalcol,
https://dlizcano.github.io/mammalcol/
BugReports: https://github.com/dlizcano/mammalcol/issues
Depends:
R (>= 2.10)
Imports:
ggplot2
Suggests:
dplyr,
finch,
geodata,
readr,
readxl,
sf,
stringr,
testthat (>= 3.0.0)
Config/testthat/edition: 3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
7 changes: 5 additions & 2 deletions R/mammalmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#' It is advised to run first the search_mammalcol function.
#'
#' @param species A character string containing the name of the species to plot the map.
#'
#'
#' @return A map for the species.
#'
Expand All @@ -17,6 +18,8 @@
#' species <- "Tapirus pinchaque"
#' mammalmap(species)
#'
#' @importFrom rlang taxon
#' @importFrom rlang colmap
#' @export
mammalmap <- function(species){

Expand All @@ -34,8 +37,8 @@ mammalmap <- function(species){
distribution_list <-
strsplit(taxon$distribution, "\\|") # trimws () removes spaces

deptos <- as.data.frame( cbind(Depto=unique(colmap$NAME_1), fill="white"))
sp_id <- which(taxon$scientificName==species)
deptos <- as.data.frame(cbind(Depto=unique(colmap$NAME_1), fill="white"))
sp_id <- which(taxon$scientificName == species)
unos <- trimws(distribution_list[[ sp_id ]]) # species number

# nested loop to get deptos
Expand Down
2 changes: 2 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ mammalmap <- function(species){
# mammalcol <img src="man/figures/logo.png" align="right" height="139" alt="" />
<!-- badges: start -->
[![R-CMD-check](https://github.com/dlizcano/mammalcol/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dlizcano/mammalcol/actions/workflows/R-CMD-check.yaml)
[![Codecov test coverage](https://codecov.io/gh/dlizcano/mammalcol/branch/main/graph/badge.svg)](https://app.codecov.io/gh/dlizcano/mammalcol?branch=main)
[![CRAN status](https://www.r-pkg.org/badges/version/mammalcol)](https://CRAN.R-project.org/package=mammalcol)
<!-- badges: end -->

The goal of mammalcol is to allow easy access to the List of Mammal Species of Colombia.
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<!-- badges: start -->

[![R-CMD-check](https://github.com/dlizcano/mammalcol/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/dlizcano/mammalcol/actions/workflows/R-CMD-check.yaml)
[![Codecov test
coverage](https://codecov.io/gh/dlizcano/mammalcol/branch/main/graph/badge.svg)](https://app.codecov.io/gh/dlizcano/mammalcol?branch=main)
[![CRAN
status](https://www.r-pkg.org/badges/version/mammalcol)](https://CRAN.R-project.org/package=mammalcol)
<!-- badges: end -->

The goal of mammalcol is to allow easy access to the List of Mammal
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
comment: false

coverage:
status:
project:
default:
target: auto
threshold: 1%
informational: true
patch:
default:
target: auto
threshold: 1%
informational: true
208 changes: 208 additions & 0 deletions data-raw/convert_tables.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@

require(readr)
require(geodata)
require(finch)
library(stringr)
library(dplyr)
library(readxl)


###########
# read ipt
##########

ipt.files <-
dwca_read(
"https://ipt.biodiversidad.co/sib/archive.do?r=mamiferos_col",
read = T,
na.strings = "",
encoding = "UTF-8"
)

taxon <- ipt.files$data$taxon.txt
distribution <- ipt.files$data$distribution.txt
vernacularname <- ipt.files$data$vernacularname.txt


####################
# read from had disk
####################

colmap <- sf::st_as_sf(gadm(country="COL", level=1, path=tempdir()))
#Let’s apply st_simplify with a tolerance of 1km:
colmap <- st_simplify(colmap, preserveTopology = FALSE, dTolerance = 1000)

# taxon <- read_delim("C:/Users/usuario/Downloads/mammal_col_2024/taxon.csv",
# delim = "\t", escape_double = FALSE)

# distribution <- read_delim("C:/Users/usuario/Downloads/mammal_col_2024/distribution.csv",
# delim = "\t", escape_double = FALSE)


MDD <- read_csv("C:/Users/usuario/Downloads/mammal_col_2024/MDD_v1.12.1_6718species.csv")
#vernacularname <- read_delim("C:/Users/usuario/Downloads/mammal_col_2024/vernacularname.csv",
# delim = "\t", escape_double = FALSE,
# trim_ws = TRUE) %>% filter(language=="es")


redlist <- read_excel("C:/Users/usuario/Downloads/mammal_col_2024/Mamíferos_Evaluados_2021-2022.xlsx")
names(redlist) <- c("scientificName", "Año de evaluación", "redlist", "Taller")

####################



MDD$scientificName <- stringr::str_replace(MDD$sciName, "_", " ")


# left join
MamCol_MDD <- left_join(taxon, MDD, by="scientificName")
MamCol_MDD$inMDD <- is.na(MamCol_MDD$sciName)
MamCol_redlist <- left_join(taxon, redlist, by="scientificName")
MamCol_distribution <- left_join(taxon, distribution, by="id")
MamCol_vernacular <- left_join(taxon, vernacularname, by="id")

####
index_notMDD <- which(is.na(MamCol_MDD$sciName))
taxon$inMDD <- 1# ifelse(is.na(MamCol_MDD$inMDD$inMDD), 0, 1) #All to 1
# convert true NA to 0
taxon$inMDD[index_notMDD] <- 0 # asign if is in MDD
taxon$Col_redlist <- MamCol_redlist$redlist # national redlist
taxon$distribution <- MamCol_distribution$locality # present in depto
taxon$source <- MamCol_distribution$source
index_endemic <- which(MamCol_distribution$establishmentMeans == "Endémica")
taxon$endemic <- "No"
taxon$endemic[index_endemic] <- "Yes"
taxon$english_name <- MamCol_MDD$mainCommonName
#taxon$spanish_name <- MamCol_vernacular$vernacularName
#taxon$name_language <- MamCol_vernacular$language



###################
fix.encoding <- function(df, originalEncoding = "UTF-8") {
numCols <- ncol(df)
df <- data.frame(df)
for (col in 1:numCols)
{
if(class(df[, col]) == "character"){
Encoding(df[, col]) <- originalEncoding
}

if(class(df[, col]) == "factor"){
Encoding(levels(df[, col])) <- originalEncoding
}
}
return(as.data.frame(df))
}
#################
# remove cols
taxon <- taxon[,-c(1,2,3,5,15,17,18)]
# mammal_colombia_2024 <- fix.encoding(taxon) # rename



#save as RDS
save (taxon, file="C:/CodigoR/Mammal_Col/mammalcol/data/taxon.rda")
# load(file="C:/CodigoR/Mammal_Col/MammalCol/data/taxon.rda")#, encoding = "UTF-8")
save (colmap, file="C:/CodigoR/Mammal_Col/MammalCol/data/colmap.rda")



#######################
# hex package logo

library(showtext)
## Loading Google fonts (http://www.google.com/fonts)
# font_add_google("Gochi Hand", "gochi")
font_add_google("Open Sans")
## Automatically use showtext to render text for future devices
showtext_auto()

library(magick)
library(hexSticker)
img.n <- image_read("C:/CodigoR/Mammal_Col/MammalCol_old/man/figures/SCMas_Small.png")
#SCMas_png <- image_convert(img.n, "png")
image_info(img.n)
sticker(img.n, package="mammalcol", p_size=20, s_x=1, s_y=.85,
s_width=1.3, s_height=1.3,
h_size=1.5,
p_color="#0c0706",
p_family="Open Sans",
p_fontface = "bold",
h_color= "#4a7092",
h_fill= "#F0F8FF",
filename="inst/figures/mammalcol_hex.png")


###############
# ocurrence by Depto

occurrence <- function(states, type = c("any", "only", "all"), taxa = NULL) {
if (length(states) == 0) stop("Please provide at least one Colombian Departamento")
type <- match.arg(type)
states <- sort(states)
# states <- paste("BR-", states, sep = "")
if (length(states) == 0) stop("Please provide at least one Colombian Departamento")
# res <- lapply(occurrences, match, states)
if (type == "any") {
#res <- lapply(res, function(x) any(!is.na(x)))
res <- subset(distribution, grepl(paste(states, collapse = "|"), occurrence))
}
if (type == "only") {
res <- subset(distribution, grepl(paste("^", paste(states, collapse = "\\|"), "$", sep = ""), occurrence))
}
if (type == "all") {
res <- subset(distribution, grepl(paste(states, collapse = ".*"), occurrence))
}
# res <- distribution[unlist(res), ]
if (nrow(res) == 0) {
return(NA)
}
if (is.null(taxa)) {
merge(all.taxa[, c("id", "family", "search.str")], res[, c("id", "occurrence")], by = "id")
} else {
merge(all.taxa[all.taxa$search.str %in% taxa, c("id", "family", "search.str")], res[, c("id", "occurrence")], by = "id")
}
}



#### test
# test <- subset(distribution, grepl(paste("^", paste("Atlántico" , collapse = "\\|"), "$", sep = ""), taxon))

distribution_list <-
strsplit(distribution$locality, "\\|") # trimws () removes spaces

# trimws(distribution_list[[55]])

mammalmap <- function(species){

deptos <- as.data.frame( cbind(Depto=unique(colmap$NAME_1), fill="white"))
sp_id <- which(taxon$scientificName==species)
unos <- trimws(distribution_list[[ sp_id ]]) # species number

# nested loop to get deptos
for (i in 1:length(deptos[,1])){
for (j in 1:length(unos)){
if(deptos$Depto[i]==unos[j]){deptos$fill[i] <- "blue"}
}
}

# make the map
ggplot(colmap) +
geom_sf(aes(fill = NAME_1)) +
scale_fill_manual(values = deptos$fill) +
# ggtitle(taxon$scientificName[25]) + #species name number
labs(subtitle = taxon$scientificName[sp_id])+
theme(legend.position="right", # locatio legend
legend.title = element_blank(),#element_text(size=7),#,
legend.text = element_text(size=7,), # text depto size
plot.subtitle = element_text(face = "italic") # italica
)#,
}





Binary file added pkgdown/favicon/apple-touch-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added pkgdown/favicon/favicon.ico
Binary file not shown.

0 comments on commit fa142f7

Please sign in to comment.