Skip to content

add offline argument to plot_geo(); closes #356 #1276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ Suggests:
png,
IRdisplay,
processx,
plotlyGeoAssets,
rstudioapi
Remotes:
tidyverse/ggplot2
19 changes: 18 additions & 1 deletion R/plotly.R
Original file line number Diff line number Diff line change
@@ -257,6 +257,9 @@ plot_mapbox <- function(data = data.frame(), ...) {
#'
#' @param data A data frame (optional).
#' @param ... arguments passed along to [plot_ly()].
#' @param offline whether or not to include geo assets so that the map
#' can be viewed with or without an internet connection. The plotlyGeoAssets
#' package is required for this functionality.
#' @export
#' @author Carson Sievert
#' @seealso [plot_ly()], [plot_mapbox()], [ggplotly()]
@@ -267,8 +270,22 @@ plot_mapbox <- function(data = data.frame(), ...) {
#' plot_geo(x = ~long, y = ~lat) %>%
#' add_markers(size = I(1))
#'
plot_geo <- function(data = data.frame(), ...) {
plot_geo <- function(data = data.frame(), ..., offline = FALSE) {
p <- plot_ly(data, ...)

if (isTRUE(offline)) {
if (system.file(package = "plotlyGeoAssets") == "") {
stop(
"The plotlyGeoAssets package is required to make 'offline' maps. ",
"Please install and try again.",
call. = FALSE
)
}
p$dependencies <- c(
list(plotlyGeoAssets::geo_assets()),
p$dependencies
)
}
# not only do we use this for is_geo(), but also setting the layout attr
# https://plot.ly/r/reference/#layout-geo
p$x$layout$mapType <- "geo"
6 changes: 5 additions & 1 deletion man/plot_geo.Rd

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