Skip to content

Commit

Permalink
Merge pull request #53 from davidcarslaw/fix/ggmap
Browse files Browse the repository at this point in the history
feat: ggmap updates
  • Loading branch information
jack-davison committed Nov 2, 2023
2 parents 7a3dabc + 6f1e2f0 commit 9cd2cd4
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 264 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: openairmaps
Title: Create Maps of Air Pollution Data
Version: 0.8.0.9004
Version: 0.8.0.9005
Authors@R: c(
person("Jack", "Davison", , "jack.davison@ricardo.com", role = c("cre", "aut")),
person("David", "Carslaw", , "david.carslaw@york.ac.uk", role = "aut")
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ These are items associated with the development version of `{openairmaps}`.

* BREAKING: The default arguments of some `polarMap()`-family functions have changed from, e.g., `NULL` to `"free"` or `"fixed"`. (#34)

* BREAKING: Due to changes in `{ggmap}`, all static polar plotting functions now require users to provide their own `ggmap` object. The `zoom` argument has also been removed. This is specifically related to the partnership of Stamen and Stadia which has put the stamen tiles behind an API. See <https://maps.stamen.com/stadia-partnership/> and <https://github.com/dkahle/ggmap/issues/353> for more information. (#52)

## New features

* Several "limit" arguments can now take one of three options: "fixed" (which forces all markers to share scales), "free" (which allows them to use different scales), or a numeric vector to define the scales. (#34) These arguments and their defaults include:
Expand Down
16 changes: 4 additions & 12 deletions R/polar_annulusMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,22 @@ annulusMap <- function(data,
#' @export
annulusMapStatic <- function(data,
pollutant = NULL,
ggmap,
period = "hour",
facet = NULL,
limits = "free",
latitude = NULL,
longitude = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(data = data,
latitude = latitude,
Expand Down Expand Up @@ -362,16 +364,6 @@ annulusMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
16 changes: 4 additions & 12 deletions R/polar_diffMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,13 +268,12 @@ diffMap <- function(before,
diffMapStatic <- function(before,
after,
pollutant = NULL,
ggmap,
limits = "free",
x = "ws",
latitude = NULL,
longitude = NULL,
facet = NULL,
zoom = 13,
ggmap = NULL,
cols = c(
"#002F70",
"#3167BB",
Expand All @@ -292,6 +291,9 @@ diffMapStatic <- function(before,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(
data = before,
Expand Down Expand Up @@ -407,16 +409,6 @@ diffMapStatic <- function(before,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
16 changes: 4 additions & 12 deletions R/polar_freqMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,22 @@ freqMap <- function(data,
#' @export
freqMapStatic <- function(data,
pollutant = NULL,
ggmap,
statistic = "mean",
breaks = "free",
latitude = NULL,
longitude = NULL,
facet = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(data = data,
latitude = latitude,
Expand Down Expand Up @@ -411,16 +413,6 @@ freqMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
16 changes: 4 additions & 12 deletions R/polar_percentileMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,22 @@ percentileMap <- function(data,
#' @export
percentileMapStatic <- function(data,
pollutant = NULL,
ggmap,
percentile = c(25, 50, 75, 90, 95),
intervals = "fixed",
latitude = NULL,
longitude = NULL,
facet = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(data = data,
latitude = latitude,
Expand Down Expand Up @@ -361,16 +363,6 @@ percentileMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
26 changes: 6 additions & 20 deletions R/polar_polarMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,8 @@ polarMap <- function(data,
#' @param facet Used for splitting the input data into different panels, passed
#' to the `type` argument of [openair::cutData()]. `facet` cannot be used if
#' multiple `pollutant` columns have been provided.
#' @param zoom The zoom level to use for the basemap, passed to
#' [ggmap::get_stamenmap()]. Alternatively, the `ggmap` argument can be used
#' for more precise control of the basemap.
#' @param ggmap By default, `openairmaps` will try to estimate an appropriate
#' bounding box for the input data and then run [ggmap::get_stamenmap()] to
#' import a basemap. The `ggmap` argument allows users to provide their own
#' `ggmap` object to override this, which allows for alternative bounding
#' boxes, map types and colours.
#' @param ggmap A `ggmap` object obtained using [ggmap::get_map()] or a similar
#' function to use as the basemap.
#' @param facet.nrow Passed to the `nrow` argument of [ggplot2::facet_wrap()].
#' @inheritDotParams openair::polarPlot -mydata -pollutant -x -limits -type
#' -cols -key -alpha -plot
Expand All @@ -327,21 +321,23 @@ polarMap <- function(data,
#' @export
polarMapStatic <- function(data,
pollutant = NULL,
ggmap,
x = "ws",
limits = "free",
upper = "fixed",
latitude = NULL,
longitude = NULL,
facet = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(
data = data,
Expand Down Expand Up @@ -458,16 +454,6 @@ polarMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
16 changes: 4 additions & 12 deletions R/polar_pollroseMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,20 +215,22 @@ pollroseMap <- function(data,
#' @export
pollroseMapStatic <- function(data,
pollutant = NULL,
ggmap,
statistic = "prop.count",
breaks = NULL,
facet = NULL,
latitude = NULL,
longitude = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(
data = data,
Expand Down Expand Up @@ -300,16 +302,6 @@ pollroseMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
16 changes: 4 additions & 12 deletions R/polar_windroseMap.R
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,22 @@ windroseMap <- function(data,
#' @return a `ggplot2` plot with a `ggmap` basemap
#' @export
windroseMapStatic <- function(data,
ggmap = NULL,
ws.int = 2,
breaks = 4,
facet = NULL,
latitude = NULL,
longitude = NULL,
zoom = 13,
ggmap = NULL,
cols = "turbo",
alpha = 1,
key = FALSE,
facet.nrow = NULL,
d.icon = 150,
d.fig = 3,
...) {
# check that there is a ggmap
check_ggmap(missing(ggmap))

# assume lat/lon
latlon <- assume_latlon(
data = data,
Expand Down Expand Up @@ -290,16 +292,6 @@ windroseMapStatic <- function(data,
d.fig = d.fig
)

# load ggmap if not provided
ggmap <-
estimate_ggmap(
ggmap = ggmap,
data = plots_df,
latitude = latitude,
longitude = longitude,
zoom = zoom
)

# create static map - deals with basics & facets
plt <-
create_static_map(
Expand Down
12 changes: 12 additions & 0 deletions R/utils-map.R
Original file line number Diff line number Diff line change
Expand Up @@ -603,3 +603,15 @@ check_multipoll <- function(vec, pollutant){
vec
}
}

#' check if ggmap has been provided
#' @noRd
check_ggmap <- function(missing) {
if (missing) {
cli::cli_abort(
c("!" = "No {.field ggmap} provided.",
"i" = "Please use {.fun ggmap::get_map} or similar to get a tileset."),
call = NULL
)
}
}
16 changes: 4 additions & 12 deletions man/annulusMapStatic.Rd

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

2 changes: 2 additions & 0 deletions man/diffMap.Rd

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

Loading

0 comments on commit 9cd2cd4

Please sign in to comment.