Skip to content

Commit

Permalink
mapzoom bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDedman committed Aug 30, 2023
1 parent 4562e06 commit 5e8c324
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
98 changes: 49 additions & 49 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -1,52 +1,3 @@
readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
# add check to see whether csv is categorical.
if (class(tmp[, 1][[1]]) != "character") stop("csv is not a categorical/factorial variable")
tmp <- tmp |>
dplyr::mutate(ycentred = y - mean(y)) |>
dplyr::rename(Category = tidyselect::last_col(offset = 2)) |> # no first_col option
# alter axis titles
dplyr::mutate(Category = dplyr::case_match(Category,
"australes" ~ "Australes",
# add more here. Or do this in csv
.default = Category))
tmp <-
readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
# add check to see whether csv is categorical.
if (class(tmp[, 1][[1]]) != "character") stop("csv is not a categorical/factorial variable")
tmp <- tmp |>
dplyr::mutate(ycentred = y - mean(y)) |>
dplyr::rename(Category = tidyselect::last_col(offset = 2)) |> # no first_col option
# re-order the x axis for categorical variables so they are either
# 1) in order from high to low or
dplyr::arrange(ycentred)
tmp <-
readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
# add check to see whether csv is categorical.
if (class(tmp[, 1][[1]]) != "character") stop("csv is not a categorical/factorial variable")
tmp <- tmp |>
dplyr::mutate(ycentred = y - mean(y)) |>
dplyr::rename(Category = tidyselect::last_col(offset = 2)) |> # no first_col option
# re-order the x axis for categorical variables so they are either
# 1) in order from high to low or
dplyr::arrange(ycentred) |>
dplyr::mutate(Category = ordered(Category, levels = Category))
tmp <-
readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
# add check to see whether csv is categorical.
if (class(tmp[, 1][[1]]) != "character") stop("csv is not a categorical/factorial variable")
tmp <- tmp |>
dplyr::mutate(ycentred = y - mean(y)) |>
dplyr::rename(Category = tidyselect::last_col(offset = 2)) |> # no first_col option
# re-order the x axis for categorical variables so they are either
# 1) in order from high to low or
dplyr::arrange(ycentred)
tmp <-
readr::read_csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-03_Frances_Naomi/2023-02-21 categorical variables issue/count_elasmo/Gaus_Best_line_isl_grp.csv")
# add check to see whether csv is categorical.
if (class(tmp[, 1][[1]]) != "character") stop("csv is not a categorical/factorial variable")
tmp <- tmp |>
dplyr::mutate(ycentred = y - mean(y)) |>
dplyr::rename(Category = tidyselect::last_col(offset = 2)) |> # no first_col option
# re-order the x axis for categorical variables so they are either
# 1) in order from high to low or
dplyr::arrange(ycentred) |>
Expand Down Expand Up @@ -510,3 +461,52 @@ alerts = FALSE,
randomvar = TRUE,
smooth = TRUE,
savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/")
library(gbm.auto)
RSandVSsamples <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/NarrowedVars_07272023_RSVS.csv")
MatureRSGrid <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/MatureRSGrid.csv")
RSVScropmap <- sf::st_read(dsn = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/Map/CroppedMap/Crop_Map.shp")
setwd("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/")
# but gbm.mapsf not outputting data, whereas gbm.map IS for b&w. Why?
# Abundance_Preds_only.csv col order = lat lon pred. Is this way due to changed order in grids?
# gbm.auto L1787 : gbm.mapsf(predabund = grids[c(gridslat, gridslon, predabund)],
# gbm.mapsf function defaults:
# gbm.mapsf <- function(
# predabund = NULL, # predicted abundance data frame produced by gbm.auto (Abundance_Preds_only.csv), with Latitude, Longitude, and Predicted Abundance columns.
# predabundlon = 2, # Longitude column number.
# predabundlat = 1, # Latitude column number.
# predabundpreds = 3,
# Looks right
predabund <- read.csv("/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/Abundance_Preds_only.csv")
gbm.auto::gbm.mapsf(predabund = predabund,
# predabundlon = 2, # Longitude column number.
# predabundlat = 1, # Latitude column number.
# predabundpreds = 3, # Predicted abundance column number.
# myLocation = NULL, # location for extents, format c(xmin, ymin, xmax, ymax).
# trim = TRUE, # remove NA & 0 values and crop to remaining date extents? Default TRUE.
# scale100 = FALSE, # scale Predicted Abundance to 100? Default FALSE.
# gmapsAPI = NULL, # enter your Google maps API here, quoted character string
# mapsource = "google", # Source for ggmap::get_map; uses Stamen as fallback if no Google Maps API present. Options: "google", "stamen", "gbm.basemap".
# googlemap = TRUE, # If pulling basemap from Google maps, this sets expansion factors since
# # Google Maps tiling zoom setup doesn't align to myLocation extents.
# maptype = "satellite",
# darkenproportion = 0, # amount to darken the basemap, 0-1.
# mapzoom = 6, # google: 3 (continent) - 21 (building). stamen: 0-18
shape = RSVScropmap, # If mapsource is "gbm.basemap", enter the full path to gbm.basemaps downloaded map, typically Crop_Map.shp, including the .shp.
# expandfactor = 0, # extents expansion factor for basemap. default was 1.6
# colourscale = "viridis", # Scale fill colour scheme to use, default "viridis", other option is "gradient".
# colorscale = NULL, # Scale fill colour scheme to use, default NULL, populating this will overwrite colourscale.
# heatcolours = c("white", "yellow", "orange","red", "brown4"), # Vector of colours if gradient selected for colourscale, defaults to heatmap theme.
# colournumber = 8, # Number of colours to spread heatcolours over, if gradient selected for colourscale. Default 8.
studyspecies = "TEST",
# plottitle = paste0("Predicted abundance of ", studyspecies),
# plotsubtitle = "CPUE", # data %>% distinct(ID) %>% nrow() # 13
# legendtitle = "CPUE",
# plotcaption = paste0("gbm.auto::gbm.map, ", lubridate::today()),
# axisxlabel = "Longitude",
# axisylabel = "Latitude",
legendposition = c(0.05, 0.18),
# fontsize = 12,
# fontfamily = "Times New Roman",
# filesavename = paste0(lubridate::today(), "_", studyspecies, "_", legendtitle, ".png"),
savedir = "/home/simon/Documents/Si Work/PostDoc Work/Gbmauto help/2022-12-06 Cat Wells/CPUESpawnVS/gbmmapsftest"
)
2 changes: 1 addition & 1 deletion R/gbm.mapsf.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ gbm.mapsf <- function(
myLocation <- c(xmin, ymin, xmax, ymax)
}

if (mapsource == "google" & mapzoom == NULL) {
if (mapsource == "google" & is.null(mapzoom)) {
# Created lookup table for degrees to mapzoom by eye at all zoom levels
lonvec <- c(0.00042724609375,
0.0008544921875,
Expand Down

0 comments on commit 5e8c324

Please sign in to comment.