Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -69,6 +69,7 @@ Suggests:
png,
IRdisplay,
processx,
plotlyGeoAssets,
rstudioapi
Remotes:
tidyverse/ggplot2
Expand Down
19 changes: 18 additions & 1 deletion R/plotly.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -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"
Expand Down
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.