Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fixes related to #29
Browse files Browse the repository at this point in the history
make sure all map_ methods work for when occ_search and occ_data give back > 1 taxa results
wasnt working before this fix
  • Loading branch information
sckott committed Mar 20, 2018
1 parent e69ca3d commit c3bdf1c
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 37 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description: Utilities for visualizing species occurrence data. Includes
functions to visualize occurrence data from 'spocc', 'rgbif',
and other packages. Mapping options included for base R plots, 'ggplot2',
'ggmap', 'leaflet' and 'GitHub' 'gists'.
Version: 0.3.6.9210
Version: 0.3.6.9410
License: MIT + file LICENSE
Authors@R: person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "[email protected]", comment = c(ORCID = "0000-0003-1444-9135"))
Expand All @@ -22,7 +22,8 @@ Imports:
rworldmap,
RColorBrewer,
jsonlite,
gistr
gistr,
data.table
Suggests:
testthat,
ggmap,
Expand Down
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ README.md: README.Rmd
rm -f $@.bak

move:
cp inst/vign/mapr_vignette.md vignettes
cp -rf inst/vign/img/* vignettes/img/
cp inst/vign/mapr_vignette.md vignettes
cp -rf inst/vign/img/* vignettes/img/

rmd2md:
cd vignettes;\
mv mapr_vignette.md mapr_vignette.Rmd
cd vignettes;\
mv mapr_vignette.md mapr_vignette.Rmd



Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ S3method(map_ggmap,SpatialPointsDataFrame)
S3method(map_ggmap,data.frame)
S3method(map_ggmap,default)
S3method(map_ggmap,gbif)
S3method(map_ggmap,gbif_data)
S3method(map_ggmap,occdat)
S3method(map_ggmap,occdatind)
S3method(map_ggplot,SpatialPoints)
Expand All @@ -22,20 +23,23 @@ S3method(map_gist,SpatialPointsDataFrame)
S3method(map_gist,data.frame)
S3method(map_gist,default)
S3method(map_gist,gbif)
S3method(map_gist,gbif_data)
S3method(map_gist,occdat)
S3method(map_gist,occdatind)
S3method(map_leaflet,SpatialPoints)
S3method(map_leaflet,SpatialPointsDataFrame)
S3method(map_leaflet,data.frame)
S3method(map_leaflet,default)
S3method(map_leaflet,gbif)
S3method(map_leaflet,gbif_data)
S3method(map_leaflet,occdat)
S3method(map_leaflet,occdatind)
S3method(map_plot,SpatialPoints)
S3method(map_plot,SpatialPointsDataFrame)
S3method(map_plot,data.frame)
S3method(map_plot,default)
S3method(map_plot,gbif)
S3method(map_plot,gbif_data)
S3method(map_plot,occdat)
S3method(map_plot,occdatind)
export(hull)
Expand Down
11 changes: 9 additions & 2 deletions R/map_ggmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_ggmap(res)
#'
#' #### many taxa
#' res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"),
#' limit = 30)
#' map_ggmap(res)
#'
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor', 'Foo bar'),
#' longitude = c(-120, -121, -123),
Expand Down Expand Up @@ -93,7 +98,8 @@ map_ggmap.gbif <- function(x, zoom = 3, point_color = "#86161f", color = NULL,
size = 3, lon = 'longitude', lat = 'latitude',
maptype = "terrain", source = "google", ...) {
check_inputs(match.call())
x <- guess_latlon(x$data, lon = 'decimalLongitude', lat = 'decimalLatitude')
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
x <- guess_latlon(x, lon = 'decimalLongitude', lat = 'decimalLatitude')
map_ggmapper(x, zoom, color, size, maptype, source)
}

Expand All @@ -102,7 +108,8 @@ map_ggmap.gbif_data <- function(x, zoom = 3, point_color = "#86161f", color = NU
size = 3, lon = 'longitude', lat = 'latitude',
maptype = "terrain", source = "google", ...) {
check_inputs(match.call())
x <- guess_latlon(x$data, lon = 'decimalLongitude', lat = 'decimalLatitude')
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
x <- guess_latlon(x, lon = 'decimalLongitude', lat = 'decimalLatitude')
map_ggmapper(x, zoom, color, size, maptype, source)
}

Expand Down
11 changes: 9 additions & 2 deletions R/map_ggplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_ggplot(res)
#'
#' #### many taxa
#' res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"),
#' limit = 30)
#' map_ggplot(res)
#'
#' ### add a convex hull
#' map_ggplot(res) + hull()
#'
Expand Down Expand Up @@ -96,7 +101,8 @@ map_ggplot.gbif <- function(x, map = "world", point_color = "#86161f",
color = NULL, size = 3, lon = 'longitude',
lat = 'latitude', ...) {
check_inputs(match.call())
make_amap(dat_cleaner(x$data, lon = 'decimalLongitude',
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
make_amap(dat_cleaner(x, lon = 'decimalLongitude',
lat = 'decimalLatitude'), map, color, size)
}

Expand All @@ -105,7 +111,8 @@ map_ggplot.gbif_data <- function(x, map = "world", point_color = "#86161f",
color = NULL, size = 3, lon = 'longitude',
lat = 'latitude', ...) {
check_inputs(match.call())
make_amap(dat_cleaner(x$data, lon = 'decimalLongitude',
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
make_amap(dat_cleaner(x, lon = 'decimalLongitude',
lat = 'decimalLatitude'), map, color, size)
}

Expand Down
11 changes: 9 additions & 2 deletions R/map_gist.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_gist(res)
#'
#' #### many taxa
#' res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"),
#' limit = 30)
#' res
#' map_gist(res)
#'
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor', 'Foo bar'),
Expand Down Expand Up @@ -77,7 +84,7 @@ map_gist.occdatind <- function(x, description = "", public = TRUE,
#' @export
map_gist.gbif <- function(x, description = "", public = TRUE, browse = TRUE,
lon = 'longitude', lat = 'latitude', ...) {
x <- x$data
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
x <- re_name(x, c('decimalLatitude' = 'latitude'))
x <- re_name(x, c('decimalLongitude' = 'longitude'))
map_gister(x, description, public, browse, ...)
Expand All @@ -86,7 +93,7 @@ map_gist.gbif <- function(x, description = "", public = TRUE, browse = TRUE,
#' @export
map_gist.gbif_data <- function(x, description = "", public = TRUE, browse = TRUE,
lon = 'longitude', lat = 'latitude', ...) {
x <- x$data
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
x <- re_name(x, c('decimalLatitude' = 'latitude'))
x <- re_name(x, c('decimalLongitude' = 'longitude'))
map_gister(x, description, public, browse, ...)
Expand Down
13 changes: 11 additions & 2 deletions R/map_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_leaflet(res)
#'
#' #### many taxa
#' res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"),
#' limit = 30)
#' res
#' map_leaflet(res)
#'
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor'),
Expand Down Expand Up @@ -99,8 +106,9 @@ map_leaflet.SpatialPointsDataFrame <- function(x, lon = 'longitude',
#' @export
map_leaflet.gbif <- function(x, lon = 'longitude', lat = 'latitude',
color = NULL, size = 13, ...) {
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
make_map_ll(
dat_cleaner(x$data, lon = 'decimalLongitude', lat = 'decimalLatitude'),
dat_cleaner(x, lon = 'decimalLongitude', lat = 'decimalLatitude'),
color = color,
size = size
)
Expand All @@ -109,8 +117,9 @@ map_leaflet.gbif <- function(x, lon = 'longitude', lat = 'latitude',
#' @export
map_leaflet.gbif_data <- function(x, lon = 'longitude', lat = 'latitude',
color = NULL, size = 13, ...) {
x <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
make_map_ll(
dat_cleaner(x$data, lon = 'decimalLongitude', lat = 'decimalLatitude'),
dat_cleaner(x, lon = 'decimalLongitude', lat = 'decimalLatitude'),
color = color,
size = size
)
Expand Down
10 changes: 8 additions & 2 deletions R/map_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_plot(res)
#' #### many taxa
#' res <- occ_data(scientificName = c("Puma concolor", "Quercus lobata"),
#' limit = 30)
#' res
#' map_plot(res)
#'
#'
#' ## data.frame
#' df <- data.frame(
Expand Down Expand Up @@ -104,7 +110,7 @@ map_plot.occdatind <- function(x, lon = 'longitude', lat = 'latitude',
#' @export
map_plot.gbif <- function(x, lon = 'longitude', lat = 'latitude', color = NULL,
size = 1, pch = 16, hull = FALSE, ...) {
df <- x$data
df <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
df <- guess_latlon(df)
df <- df[stats::complete.cases(df$latitude, df$longitude), ]
df <- df[df$longitude != 0, ]
Expand All @@ -116,7 +122,7 @@ map_plot.gbif <- function(x, lon = 'longitude', lat = 'latitude', color = NULL,
#' @export
map_plot.gbif_data <- function(x, lon = 'longitude', lat = 'latitude', color = NULL,
size = 1, pch = 16, hull = FALSE, ...) {
df <- x$data
df <- if ("data" %in% names(x)) x$data else bdt(lapply(x, function(z) z$data))
df <- guess_latlon(df)
df <- df[stats::complete.cases(df$latitude, df$longitude), ]
df <- df[df$longitude != 0, ]
Expand Down
6 changes: 6 additions & 0 deletions R/zzz.r
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ check_inputs <- function(x) {
call. = FALSE)
}
}

bdt <- function(x) {
(bb <- data.table::setDF(
data.table::rbindlist(x, fill = TRUE, use.names = TRUE)
))
}
21 changes: 17 additions & 4 deletions man/map_ggmap.Rd

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

15 changes: 11 additions & 4 deletions man/map_ggplot.Rd

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

22 changes: 18 additions & 4 deletions man/map_gist.Rd

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

Loading

0 comments on commit c3bdf1c

Please sign in to comment.