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

Commit

Permalink
fix #29 support output of rgbif::occ_data in map functions, bump dev …
Browse files Browse the repository at this point in the history
…version
  • Loading branch information
sckott committed Mar 20, 2018
1 parent 9301ea0 commit e69ca3d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ gistmap*
^CONDUCT\.md$
^cran-comments\.md$
^codemeta\.json$
.github
\.github
2 changes: 1 addition & 1 deletion 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.5.9210
Version: 0.3.6.9210
License: MIT + file LICENSE
Authors@R: person("Scott", "Chamberlain", role = c("aut", "cre"),
email = "[email protected]", comment = c(ORCID = "0000-0003-1444-9135"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export(map_gist)
export(map_leaflet)
export(map_plot)
export(occ2sp)
export(style_geojson)
import(leaflet)
importFrom(ggplot2,aes)
importFrom(ggplot2,element_blank)
Expand Down
15 changes: 15 additions & 0 deletions R/map_ggmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@
#'
#' ## rgbif
#' library("rgbif")
#' ### occ_search() output
#' res <- occ_search(scientificName = "Puma concolor", limit = 100)
#' map_ggmap(res)
#'
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_ggmap(res)
#'
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor', 'Foo bar'),
Expand Down Expand Up @@ -91,6 +97,15 @@ map_ggmap.gbif <- function(x, zoom = 3, point_color = "#86161f", color = NULL,
map_ggmapper(x, zoom, color, size, maptype, source)
}

#' @export
map_ggmap.gbif_data <- 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')
map_ggmapper(x, zoom, color, size, maptype, source)
}

#' @export
map_ggmap.data.frame <- function(x, zoom = 3, point_color = "#86161f",
color = NULL, size = 3, lon = 'longitude',
Expand Down
14 changes: 14 additions & 0 deletions R/map_gist.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
#'
#' ## rgbif
#' library("rgbif")
#' ### occ_search() output
#' res <- occ_search(scientificName = "Puma concolor", limit = 100)
#' map_gist(res)
#'
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_gist(res)
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor', 'Foo bar'),
Expand Down Expand Up @@ -78,6 +83,15 @@ map_gist.gbif <- function(x, description = "", public = TRUE, browse = TRUE,
map_gister(x, description, public, browse, ...)
}

#' @export
map_gist.gbif_data <- function(x, description = "", public = TRUE, browse = TRUE,
lon = 'longitude', lat = 'latitude', ...) {
x <- x$data
x <- re_name(x, c('decimalLatitude' = 'latitude'))
x <- re_name(x, c('decimalLongitude' = 'longitude'))
map_gister(x, description, public, browse, ...)
}

#' @export
map_gist.data.frame <- function(x, description = "", public = TRUE,
browse = TRUE, lon = 'longitude',
Expand Down
15 changes: 15 additions & 0 deletions R/map_leaflet.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@
#'
#' ## SpatialPointsDataFrame class
#' library("rgbif")
#' ### occ_search() output
#' res <- occ_search(scientificName = "Puma concolor", limit = 100)
#' x <- res$data
#' library("sp")
#' x <- x[stats::complete.cases(x$decimalLatitude, x$decimalLongitude), ]
#' coordinates(x) <- ~decimalLongitude+decimalLatitude
#' map_leaflet(x)
#'
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_leaflet(res)
#'
#' ## data.frame
#' df <- data.frame(name = c('Poa annua', 'Puma concolor'),
Expand Down Expand Up @@ -101,6 +106,16 @@ map_leaflet.gbif <- function(x, lon = 'longitude', lat = 'latitude',
)
}

#' @export
map_leaflet.gbif_data <- function(x, lon = 'longitude', lat = 'latitude',
color = NULL, size = 13, ...) {
make_map_ll(
dat_cleaner(x$data, lon = 'decimalLongitude', lat = 'decimalLatitude'),
color = color,
size = size
)
}

#' @export
map_leaflet.data.frame <- function(x, lon = 'longitude', lat = 'latitude',
color = NULL, size = 13, ...) {
Expand Down
17 changes: 17 additions & 0 deletions R/map_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
#'
#' ## rgbif
#' library("rgbif")
#' ### occ_search() output
#' res <- occ_search(scientificName = "Puma concolor", limit = 100)
#' map_plot(res)
#' map_plot(res, hull = TRUE)
#'
#' ### occ_data() output
#' res <- occ_data(scientificName = "Puma concolor", limit = 100)
#' map_plot(res)
#'
#' ## data.frame
#' df <- data.frame(
Expand Down Expand Up @@ -108,6 +113,18 @@ map_plot.gbif <- function(x, lon = 'longitude', lat = 'latitude', color = NULL,
plot_er(df, size, hull, ...)
}

#' @export
map_plot.gbif_data <- function(x, lon = 'longitude', lat = 'latitude', color = NULL,
size = 1, pch = 16, hull = FALSE, ...) {
df <- x$data
df <- guess_latlon(df)
df <- df[stats::complete.cases(df$latitude, df$longitude), ]
df <- df[df$longitude != 0, ]
df <- check_colors(df, color)
sp::coordinates(df) <- ~longitude + latitude
plot_er(df, size, hull, ...)
}

#' @export
map_plot.data.frame <- function(x, lon = 'longitude', lat = 'latitude',
color = NULL, size = 1, pch = 16,
Expand Down
10 changes: 6 additions & 4 deletions man-roxygen/args.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#' @param x The data. An object of class \code{occdat}, \code{occdatind},
#' \code{gbif}, \code{SpatialPoints}, \code{SpatialPointsDataFrame}, or
#' \code{data.frame}. The package \pkg{spocc} needed for
#' \code{gbif}, \code{gbif_data}, \code{SpatialPoints},
#' \code{SpatialPointsDataFrame}, or \code{data.frame}. The package
#' \pkg{spocc} needed for
#' the first two, and \pkg{rgbif} needed for the third. When \code{data.frame}
#' input, any number of columns allowed, but with at least the following:
#' name (the taxonomic name), latitude (in dec. deg.), longitude (in dec. deg.)
#' @param lon,lat (character) Longitude and latitude variable names. Ignored
#' unless \code{data.frame} input to \code{x} parameter. We attempt to guess, but
#' if nothing close, we stop. Default: \code{longitude} and \code{latitude}
#' unless \code{data.frame} input to \code{x} parameter. We attempt to guess,
#' but if nothing close, we stop. Default: \code{longitude} and
#' \code{latitude}
31 changes: 31 additions & 0 deletions man/style_geojson.Rd

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

0 comments on commit e69ca3d

Please sign in to comment.