Skip to content

Commit 6f7d400

Browse files
authored
Merge pull request #20 from marcosci/19-deprecated-ggplot2-function-aes_string
replace deprecated aes_string with aes and tidyselect with rlang .data
2 parents 9197231 + 1f7034e commit 6f7d400

5 files changed

Lines changed: 44 additions & 25 deletions

File tree

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
^README\.qmd$
1111
^CRAN-SUBMISSION$
1212
^cran-comments\.md$
13+
^private$
14+
^\.Renviron$
15+
^\.Rprofile$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55

66
private
7+
.Renviron

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ Imports:
2525
ggplot2,
2626
magrittr,
2727
raster,
28+
rlang,
2829
scico,
2930
sf,
3031
stars,
3132
tidyr
3233
Encoding: UTF-8
3334
LazyData: true
3435
Roxygen: list(markdown = TRUE)
35-
RoxygenNote: 7.3.2
36+
RoxygenNote: 7.3.3

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export(plot_tiltedmaps)
44
export(tilt_map)
55
import(raster)
66
importFrom(magrittr,"%>%")
7+
importFrom(rlang,.data)
78
importFrom(sf,st_geometry_type)

R/plot_tiltmaps.R

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#'
1515
#' @return A `ggplot` object with stacked maps.
1616
#' @importFrom sf st_geometry_type
17+
#' @importFrom rlang .data
1718
#' @export
1819
#' @examples
1920
#' \donttest{
@@ -43,28 +44,40 @@ plot_tiltedmaps <- function(map_list, layer = NA, palette = "viridis", color = "
4344
#if(!palette %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9], scico::scico_palette_names())) stop("palette should be a palette name from the \link[viridis]{viridis} or \link[scico]{scico} package.")
4445

4546
## plot ----
46-
map_tilt <- ggplot2::ggplot() +
47-
ggplot2::geom_sf(
48-
data = map_list[[1]],
49-
ggplot2::aes_string(fill = layer[[1]],
50-
color = layer[[1]]), size = 0.01
51-
) +
52-
{
53-
if (palette[1] %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9]))
54-
ggplot2::scale_fill_viridis_c(option = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
55-
} +
56-
{
57-
if (palette[1] %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9]))
58-
ggplot2::scale_color_viridis_c(option = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
59-
} +
60-
{
61-
if (palette[1] %in% scico::scico_palette_names())
62-
scico::scale_fill_scico(palette = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
63-
} +
64-
{
65-
if (palette[1] %in% scico::scico_palette_names())
66-
scico::scale_color_scico(palette = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
67-
}
47+
map_tilt <- ggplot2::ggplot()
48+
49+
# Handle first layer with NA check (consistent with loop for i >= 2)
50+
if (!is.na(layer[[1]])) {
51+
map_tilt <- map_tilt +
52+
ggplot2::geom_sf(
53+
data = map_list[[1]],
54+
ggplot2::aes(fill = .data[[layer[[1]]]],
55+
color = .data[[layer[[1]]]]), size = 0.01
56+
) +
57+
{
58+
if (palette[1] %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9]))
59+
ggplot2::scale_fill_viridis_c(option = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
60+
} +
61+
{
62+
if (palette[1] %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9]))
63+
ggplot2::scale_color_viridis_c(option = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
64+
} +
65+
{
66+
if (palette[1] %in% scico::scico_palette_names())
67+
scico::scale_fill_scico(palette = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
68+
} +
69+
{
70+
if (palette[1] %in% scico::scico_palette_names())
71+
scico::scale_color_scico(palette = palette[1], direction = direction[1], begin = begin[1], end = end[1], alpha = alpha[1], guide = "none")
72+
}
73+
} else {
74+
map_tilt <- map_tilt +
75+
ggplot2::geom_sf(
76+
data = map_list[[1]],
77+
color = color[1],
78+
alpha = alpha[1]
79+
)
80+
}
6881

6982

7083

@@ -76,8 +89,8 @@ plot_tiltedmaps <- function(map_list, layer = NA, palette = "viridis", color = "
7689
ggnewscale::new_scale_color() +
7790
ggplot2::geom_sf(
7891
data = map_list[[i]],
79-
ggplot2::aes_string(fill = layer[[i]],
80-
color = layer[[i]]), size = .5
92+
ggplot2::aes(fill = .data[[layer[[i]]]],
93+
color = .data[[layer[[i]]]]), size = .5
8194
) +
8295
{
8396
if (palette[i] %in% c("viridis", "inferno", "magma", "plasma", "cividis", "mako", "rocket", "turbo", letters[1:9]))

0 commit comments

Comments
 (0)