diff --git a/R/mammalmap.R b/R/mammalmap.R index de18b73..a97926c 100644 --- a/R/mammalmap.R +++ b/R/mammalmap.R @@ -25,70 +25,73 @@ #' @importFrom mammalcol taxon #' @importFrom mammalcol colmap #' @export -mammalmap <- function(species, legend=TRUE){ - - if (!requireNamespace("ggplot2", quietly = TRUE)) +mammalmap <- function(species, legend = TRUE) { + if (!requireNamespace("ggplot2", quietly = TRUE)) { install.packages("ggplot2") - if (!requireNamespace("sf", quietly = TRUE)) + } + if (!requireNamespace("sf", quietly = TRUE)) { install.packages("sf") - + } + if (missing(species)) { stop("Argument species was not included") } - + if (!is.character(species)) { stop(paste0("Argument species must be a character, not ", class(species))) } - + if (!is.logical(legend)) { stop(paste0("Argument legend must be logical, not ", class(legend))) } - + # require("ggplot2") # require("sf") - - #load("data/colmap.rda") - #load("data/taxon.rda") - - #data(mammalcol::taxon) - #data(mammalcol::colmap) - + + # load("data/colmap.rda") + # load("data/taxon.rda") + + # data(mammalcol::taxon) + # data(mammalcol::colmap) + distribution_list <- strsplit(taxon$distribution, "\\|") # trimws () removes spaces - - deptos <- as.data.frame(cbind(Depto=unique(colmap$NAME_1), fill="white")) + + 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 - + 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"} + 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 - # if legend true - if(legend==TRUE) { - mapa <- ggplot2::ggplot(colmap) + + # if legend true + if (legend == TRUE) { + mapa <- ggplot2::ggplot(colmap) + ggplot2::geom_sf(ggplot2::aes(fill = NAME_1)) + ggplot2::scale_fill_manual(values = deptos$fill) + # ggtitle(taxon$scientificName[25]) + #species name number - ggplot2::labs(subtitle = taxon$scientificName[sp_id])+ - ggplot2::theme(legend.position="right", # location legend - legend.title = ggplot2::element_blank(),#element_text(size=7),#, - legend.text = ggplot2::element_text(size=8,), # text depto size - plot.subtitle = ggplot2::element_text(face = "italic") # italica + ggplot2::labs(subtitle = taxon$scientificName[sp_id]) + + ggplot2::theme( + legend.position = "right", # location legend + legend.title = ggplot2::element_blank(), # element_text(size=7),#, + legend.text = ggplot2::element_text(size = 8, ), # text depto size + plot.subtitle = ggplot2::element_text(face = "italic") # italica ) - }else{ # if legend false - mapa <- ggplot2::ggplot(colmap) + + } else { # if legend false + mapa <- ggplot2::ggplot(colmap) + ggplot2::geom_sf(ggplot2::aes(fill = NAME_1), show.legend = FALSE) + # removes legend ggplot2::scale_fill_manual(values = deptos$fill) + # ggtitle(taxon$scientificName[25]) + #species name number ggplot2::labs(subtitle = taxon$scientificName[sp_id]) + - ggplot2::theme(plot.subtitle = ggplot2::element_text(face = "italic") - )# italica + ggplot2::theme(plot.subtitle = ggplot2::element_text(face = "italic")) # italica } - -return(mapa) + + return(mapa) } # end function diff --git a/R/onload.R b/R/onload.R index b05c0b1..3d5a31c 100644 --- a/R/onload.R +++ b/R/onload.R @@ -1,10 +1,9 @@ - .onAttach <- function(lib, pkg) { packageStartupMessage("This is mammalcol ", - utils::packageDescription("mammalcol", - fields = "Version" - ), - appendLF = TRUE + utils::packageDescription("mammalcol", + fields = "Version" + ), + appendLF = TRUE ) } @@ -20,7 +19,7 @@ show_progress <- function() { .onLoad <- function(libname, pkgname) { opt <- options() - opt_mammalcol<- list( + opt_mammalcol <- list( mammalcol.show_progress = TRUE ) to_set <- !(names(opt_mammalcol) %in% names(opt)) diff --git a/R/search_mammalcol.R b/R/search_mammalcol.R index 56ce12c..f64c2d4 100644 --- a/R/search_mammalcol.R +++ b/R/search_mammalcol.R @@ -30,7 +30,7 @@ search_mammalcol <- function(splist, max_distance = 0.2) { if (missing(splist)) { stop("Argument splist was not defined") } - + if (is.factor(splist)) { splist <- as.character(splist) } @@ -38,18 +38,22 @@ search_mammalcol <- function(splist, max_distance = 0.2) { splist_st <- standardize_names(splist) dupes_splist_st <- find_duplicates(splist_st) - if(length(dupes_splist_st) != 0 ){ - message("The following names are repeated in the 'splist': ", - paste(dupes_splist_st, collapse = ", ")) + if (length(dupes_splist_st) != 0) { + message( + "The following names are repeated in the 'splist': ", + paste(dupes_splist_st, collapse = ", ") + ) } splist_std <- unique(splist_st) # create an output data container output_matrix <- matrix(nrow = length(splist_std), ncol = 21) # two more - colnames(output_matrix) <- c("name_submitted", - names(taxon), - "Distance") - + colnames(output_matrix) <- c( + "name_submitted", + names(taxon), + "Distance" + ) + # loop code to find the matching string for (i in seq_along(splist_std)) { @@ -62,32 +66,31 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # fuzzy and exact match matches <- agrep(splist_std[i], - taxon$scientificName, # base data column - max.distance = max_distance_fixed, - value = TRUE) + taxon$scientificName, # base data column + max.distance = max_distance_fixed, + value = TRUE + ) # check non matching result if (length(matches) == 0) { row_data <- rep("nill", 19) # number of columns - } - else if (length(matches) != 0){ # match result + } else if (length(matches) != 0) { # match result dis_value <- as.numeric(utils::adist(splist_std[i], matches)) matches1 <- matches[dis_value <= max_distance_fixed] dis_val_1 <- dis_value[dis_value <= max_distance_fixed] - if (length(matches1) == 0){ + if (length(matches1) == 0) { row_data <- rep("nill", 19) # number of columns - } - else if (length(matches1) != 0){ - row_data <- as.matrix(taxon[taxon$scientificName %in% matches1,]) + } else if (length(matches1) != 0) { + row_data <- as.matrix(taxon[taxon$scientificName %in% matches1, ]) } } # distance value - if(is.null(nrow(row_data))){ + if (is.null(nrow(row_data))) { dis_value_1 <- "nill" - } else{ - dis_value_1 <- utils::adist(splist_std[i], row_data[,2]) + } else { + dis_value_1 <- utils::adist(splist_std[i], row_data[, 2]) } output_matrix[i, ] <- @@ -97,7 +100,6 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # Output output <- as.data.frame(output_matrix) # rownames(output) <- NULL - output <- output[,-2]# delete the id column - return(output[output$scientificName != "nill",]) + output <- output[, -2] # delete the id column + return(output[output$scientificName != "nill", ]) } - diff --git a/R/sp_by_depto.R b/R/sp_by_depto.R index 2b6d375..8313ba6 100644 --- a/R/sp_by_depto.R +++ b/R/sp_by_depto.R @@ -31,12 +31,12 @@ sp_by_depto <- 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 <- lapply(res, function(x) any(!is.na(x))) res <- subset(distribution, grepl(paste(states, collapse = "|"), locality)) } if (type == "only") { @@ -50,10 +50,10 @@ sp_by_depto <- function(states, type = c("any", "only", "all"), taxa = NULL) { return(NA) } if (is.null(taxa)) { - merge(taxon[, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[,-1] + merge(taxon[, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[, -1] # removes id } else { - merge(taxon[taxon$order %in% taxa, c("scientificName", "family", "order", "id" )], res[, c("id", "locality")], by = "id")[,-1] + merge(taxon[taxon$order %in% taxa, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[, -1] # removes id } } diff --git a/README.Rmd b/README.Rmd index 311e712..bb1f98c 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,9 +13,9 @@ knitr::opts_chunk$set( ) ############# -load(file="C:/CodigoR/Mammal_Col/MammalCol/data/taxon.rda")#, taxon -load(file="C:/CodigoR/Mammal_Col/MammalCol/data/colmap.rda")#, colmap -load(file="C:/CodigoR/Mammal_Col/MammalCol/data/distribution.rda")#, disribution +load(file = "C:/CodigoR/Mammal_Col/MammalCol/data/taxon.rda") # , taxon +load(file = "C:/CodigoR/Mammal_Col/MammalCol/data/colmap.rda") # , colmap +load(file = "C:/CodigoR/Mammal_Col/MammalCol/data/distribution.rda") # , disribution ############ search_mammalcol <- function(splist, max_distance = 0.2) { @@ -27,18 +27,22 @@ search_mammalcol <- function(splist, max_distance = 0.2) { splist_st <- standardize_names(splist) dupes_splist_st <- find_duplicates(splist_st) - if(length(dupes_splist_st) != 0 ){ - message("The following names are repeated in the 'splist': ", - paste(dupes_splist_st, collapse = ", ")) + if (length(dupes_splist_st) != 0) { + message( + "The following names are repeated in the 'splist': ", + paste(dupes_splist_st, collapse = ", ") + ) } splist_std <- unique(splist_st) # create an output data container output_matrix <- matrix(nrow = length(splist_std), ncol = 21) # two more - colnames(output_matrix) <- c("name_submitted", - names(taxon), - "Distance") - + colnames(output_matrix) <- c( + "name_submitted", + names(taxon), + "Distance" + ) + # loop code to find the matching string for (i in seq_along(splist_std)) { @@ -51,32 +55,31 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # fuzzy and exact match matches <- agrep(splist_std[i], - taxon$scientificName, # base data column - max.distance = max_distance_fixed, - value = TRUE) + taxon$scientificName, # base data column + max.distance = max_distance_fixed, + value = TRUE + ) # check non matching result if (length(matches) == 0) { row_data <- rep("nill", 19) # number of columns - } - else if (length(matches) != 0){ # match result + } else if (length(matches) != 0) { # match result dis_value <- as.numeric(utils::adist(splist_std[i], matches)) matches1 <- matches[dis_value <= max_distance_fixed] dis_val_1 <- dis_value[dis_value <= max_distance_fixed] - if (length(matches1) == 0){ + if (length(matches1) == 0) { row_data <- rep("nill", 19) # number of columns - } - else if (length(matches1) != 0){ - row_data <- as.matrix(taxon[taxon$scientificName %in% matches1,]) + } else if (length(matches1) != 0) { + row_data <- as.matrix(taxon[taxon$scientificName %in% matches1, ]) } } # distance value - if(is.null(nrow(row_data))){ + if (is.null(nrow(row_data))) { dis_value_1 <- "nill" - } else{ - dis_value_1 <- utils::adist(splist_std[i], row_data[,2]) + } else { + dis_value_1 <- utils::adist(splist_std[i], row_data[, 2]) } output_matrix[i, ] <- @@ -86,8 +89,8 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # Output output <- as.data.frame(output_matrix) # rownames(output) <- NULL - output <- output[,-2]# delete the id column - return(output[output$scientificName != "nill",]) + output <- output[, -2] # delete the id column + return(output[output$scientificName != "nill", ]) } @@ -105,10 +108,14 @@ standardize_names <- function(splist) { hybrids <- fixed5 == fixed6 if (!all(hybrids)) { sp_hybrids <- splist[!hybrids] - warning(paste("The 'x' sign indicating hybrids have been removed in the", - "following names before search:", - paste(paste0("'", sp_hybrids, "'"), collapse = ", ")), - immediate. = TRUE, call. = FALSE) + warning( + paste( + "The 'x' sign indicating hybrids have been removed in the", + "following names before search:", + paste(paste0("'", sp_hybrids, "'"), collapse = ", ") + ), + immediate. = TRUE, call. = FALSE + ) } # Merge multiple spaces fixed7 <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", fixed6, perl = TRUE) @@ -144,72 +151,75 @@ find_duplicates <- function(vector) { ################ -mammalmap <- function(species, legend=TRUE){ - - if (!requireNamespace("ggplot2", quietly = TRUE)) +mammalmap <- function(species, legend = TRUE) { + if (!requireNamespace("ggplot2", quietly = TRUE)) { install.packages("ggplot2") - if (!requireNamespace("sf", quietly = TRUE)) + } + if (!requireNamespace("sf", quietly = TRUE)) { install.packages("sf") - + } + if (missing(species)) { stop("Argument species was not included") } - + if (!is.character(species)) { stop(paste0("Argument species must be a character, not ", class(species))) } - + if (!is.logical(legend)) { stop(paste0("Argument legend must be logical, not ", class(legend))) } - + # require("ggplot2") # require("sf") - - #load("data/colmap.rda") - #load("data/taxon.rda") - - #data(mammalcol::taxon) - #data(mammalcol::colmap) - + + # load("data/colmap.rda") + # load("data/taxon.rda") + + # data(mammalcol::taxon) + # data(mammalcol::colmap) + distribution_list <- strsplit(taxon$distribution, "\\|") # trimws () removes spaces - - deptos <- as.data.frame(cbind(Depto=unique(colmap$NAME_1), fill="white")) + + 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 - + 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"} + 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 - # if legend true - if(legend==TRUE) { - mapa <- ggplot2::ggplot(colmap) + + # if legend true + if (legend == TRUE) { + mapa <- ggplot2::ggplot(colmap) + ggplot2::geom_sf(ggplot2::aes(fill = NAME_1)) + ggplot2::scale_fill_manual(values = deptos$fill) + # ggtitle(taxon$scientificName[25]) + #species name number - ggplot2::labs(subtitle = taxon$scientificName[sp_id])+ - ggplot2::theme(legend.position="right", # location legend - legend.title = ggplot2::element_blank(),#element_text(size=7),#, - legend.text = ggplot2::element_text(size=8,), # text depto size - plot.subtitle = ggplot2::element_text(face = "italic") # italica + ggplot2::labs(subtitle = taxon$scientificName[sp_id]) + + ggplot2::theme( + legend.position = "right", # location legend + legend.title = ggplot2::element_blank(), # element_text(size=7),#, + legend.text = ggplot2::element_text(size = 8, ), # text depto size + plot.subtitle = ggplot2::element_text(face = "italic") # italica ) - }else{ # if legend false - mapa <- ggplot2::ggplot(colmap) + + } else { # if legend false + mapa <- ggplot2::ggplot(colmap) + ggplot2::geom_sf(ggplot2::aes(fill = NAME_1), show.legend = FALSE) + # removes legend ggplot2::scale_fill_manual(values = deptos$fill) + # ggtitle(taxon$scientificName[25]) + #species name number ggplot2::labs(subtitle = taxon$scientificName[sp_id]) + - ggplot2::theme(plot.subtitle = ggplot2::element_text(face = "italic") - )# italica + ggplot2::theme(plot.subtitle = ggplot2::element_text(face = "italic")) # italica } - -return(mapa) + + return(mapa) } # end mammalmap ################## @@ -221,7 +231,7 @@ sp_by_depto <- function(states, type = c("any", "only", "all"), taxa = NULL) { 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 <- lapply(res, function(x) any(!is.na(x))) res <- subset(distribution, grepl(paste(states, collapse = "|"), locality)) } if (type == "only") { @@ -235,16 +245,15 @@ sp_by_depto <- function(states, type = c("any", "only", "all"), taxa = NULL) { return(NA) } if (is.null(taxa)) { - merge(taxon[, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[,-1] + merge(taxon[, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[, -1] # removes id } else { - merge(taxon[taxon$order %in% taxa, c("scientificName", "family", "order", "id" )], res[, c("id", "locality")], by = "id")[,-1] + merge(taxon[taxon$order %in% taxa, c("scientificName", "family", "order", "id")], res[, c("id", "locality")], by = "id")[, -1] # removes id } } - ``` @@ -287,8 +296,10 @@ This is a basic example which shows you how to search mammal names in Colombia u ```{r example1, eval=TRUE, echo=TRUE} # define a vector with species to search for -splist <- c("Tapirus bairdii", "Tapirus pinchaque", "Tapirus terrestris", - "Tapirus terrestris", "Pudu mephistophiles", "Tapirus bairdii") +splist <- c( + "Tapirus bairdii", "Tapirus pinchaque", "Tapirus terrestris", + "Tapirus terrestris", "Pudu mephistophiles", "Tapirus bairdii" +) # search in database search_mammalcol(splist) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index d427031..d204ebb 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.0.9 pkgdown_sha: ~ articles: mammalcol: mammalcol.html -last_built: 2024-05-21T17:48Z +last_built: 2024-05-22T05:52Z urls: reference: https://dlizcano.github.io/mammalcol/reference article: https://dlizcano.github.io/mammalcol/articles diff --git a/getting_started.RMD b/getting_started.RMD index acfeab4..28db6b0 100644 --- a/getting_started.RMD +++ b/getting_started.RMD @@ -13,8 +13,8 @@ knitr::opts_chunk$set( ) ############# -load(file="C:/CodigoR/Mammal_Col/MammalCol/data/taxon.rda")#, taxon -load(file="C:/CodigoR/Mammal_Col/MammalCol/data/colmap.rda")#, colmap +load(file = "C:/CodigoR/Mammal_Col/MammalCol/data/taxon.rda") # , taxon +load(file = "C:/CodigoR/Mammal_Col/MammalCol/data/colmap.rda") # , colmap ############ search_mammalcol <- function(splist, max_distance = 0.2) { @@ -26,18 +26,22 @@ search_mammalcol <- function(splist, max_distance = 0.2) { splist_st <- standardize_names(splist) dupes_splist_st <- find_duplicates(splist_st) - if(length(dupes_splist_st) != 0 ){ - message("The following names are repeated in the 'splist': ", - paste(dupes_splist_st, collapse = ", ")) + if (length(dupes_splist_st) != 0) { + message( + "The following names are repeated in the 'splist': ", + paste(dupes_splist_st, collapse = ", ") + ) } splist_std <- unique(splist_st) # create an output data container output_matrix <- matrix(nrow = length(splist_std), ncol = 20) # two more - colnames(output_matrix) <- c("name_submitted", - names(taxon), - "Distance") - + colnames(output_matrix) <- c( + "name_submitted", + names(taxon), + "Distance" + ) + # loop code to find the matching string for (i in seq_along(splist_std)) { @@ -50,32 +54,31 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # fuzzy and exact match matches <- agrep(splist_std[i], - taxon$scientificName, # base data column - max.distance = max_distance_fixed, - value = TRUE) + taxon$scientificName, # base data column + max.distance = max_distance_fixed, + value = TRUE + ) # check non matching result if (length(matches) == 0) { row_data <- rep("nill", 18) # number of columns - } - else if (length(matches) != 0){ # match result + } else if (length(matches) != 0) { # match result dis_value <- as.numeric(utils::adist(splist_std[i], matches)) matches1 <- matches[dis_value <= max_distance_fixed] dis_val_1 <- dis_value[dis_value <= max_distance_fixed] - if (length(matches1) == 0){ + if (length(matches1) == 0) { row_data <- rep("nill", 18) # number of columns - } - else if (length(matches1) != 0){ - row_data <- as.matrix(taxon[taxon$scientificName %in% matches1,]) + } else if (length(matches1) != 0) { + row_data <- as.matrix(taxon[taxon$scientificName %in% matches1, ]) } } # distance value - if(is.null(nrow(row_data))){ + if (is.null(nrow(row_data))) { dis_value_1 <- "nill" - } else{ - dis_value_1 <- utils::adist(splist_std[i], row_data[,2]) + } else { + dis_value_1 <- utils::adist(splist_std[i], row_data[, 2]) } output_matrix[i, ] <- @@ -85,8 +88,8 @@ search_mammalcol <- function(splist, max_distance = 0.2) { # Output output <- as.data.frame(output_matrix) # rownames(output) <- NULL - output <- output[,-2]# delete the id column - return(output[output$scientificName != "nill",]) + output <- output[, -2] # delete the id column + return(output[output$scientificName != "nill", ]) } @@ -104,10 +107,14 @@ standardize_names <- function(splist) { hybrids <- fixed5 == fixed6 if (!all(hybrids)) { sp_hybrids <- splist[!hybrids] - warning(paste("The 'x' sign indicating hybrids have been removed in the", - "following names before search:", - paste(paste0("'", sp_hybrids, "'"), collapse = ", ")), - immediate. = TRUE, call. = FALSE) + warning( + paste( + "The 'x' sign indicating hybrids have been removed in the", + "following names before search:", + paste(paste0("'", sp_hybrids, "'"), collapse = ", ") + ), + immediate. = TRUE, call. = FALSE + ) } # Merge multiple spaces fixed7 <- gsub("(?<=[\\s])\\s*|^\\s+|\\s+$", "", fixed6, perl = TRUE) @@ -143,48 +150,51 @@ find_duplicates <- function(vector) { ################ -mammalmap <- function(species){ - - if (!requireNamespace("ggplot2", quietly = TRUE)) +mammalmap <- function(species) { + if (!requireNamespace("ggplot2", quietly = TRUE)) { install.packages("ggplot2") - if (!requireNamespace("sf", quietly = TRUE)) + } + if (!requireNamespace("sf", quietly = TRUE)) { install.packages("sf") - + } + # require("ggplot2") # require("sf") - - #load("data/colmap.rda") - #load("data/taxon.rda") - + + # load("data/colmap.rda") + # load("data/taxon.rda") + 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) - unos <- trimws(distribution_list[[ sp_id ]]) # species number - + + 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"} + 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 ggplot2::ggplot(colmap) + ggplot2::geom_sf(ggplot2::aes(fill = NAME_1)) + ggplot2::scale_fill_manual(values = deptos$fill) + # ggtitle(taxon$scientificName[25]) + #species name number - ggplot2::labs(subtitle = taxon$scientificName[sp_id])+ - ggplot2::theme(legend.position="right", # locatio legend - legend.title = ggplot2::element_blank(),#element_text(size=7),#, - legend.text = ggplot2::element_text(size=7,), # text depto size - plot.subtitle = ggplot2::element_text(face = "italic") # italica - )#, + ggplot2::labs(subtitle = taxon$scientificName[sp_id]) + + ggplot2::theme( + legend.position = "right", # locatio legend + legend.title = ggplot2::element_blank(), # element_text(size=7),#, + legend.text = ggplot2::element_text(size = 7, ), # text depto size + plot.subtitle = ggplot2::element_text(face = "italic") # italica + ) # , } - ```