diff --git a/R/misc_stars.R b/R/misc_stars.R index a29cac6f..068fc4e0 100644 --- a/R/misc_stars.R +++ b/R/misc_stars.R @@ -72,7 +72,7 @@ regular_intervals = function (x, epsilon = 1e-10) { } } -get_downsample = function(dims, px = round(dev.size("px") * (par("fin")[1] / dev.size()[1]))) { +get_downsample = function(dims, px = round(dev.size("px") * (graphics::par("fin")[1] / dev.size()[1]))) { floor(sqrt(prod(dims) / prod(px))) } diff --git a/R/process_meta.R b/R/process_meta.R index 559dd151..859a83c2 100644 --- a/R/process_meta.R +++ b/R/process_meta.R @@ -3,7 +3,7 @@ prepreprocess_meta = function(o, vp) { within(o, { vp = vp if (is.null(vp)) { - devsize = par("fin") #dev.size() MAY NOT BE EQUAL IN RSTUDIO: https://github.com/rstudio/rstudio/issues/10723 + devsize = graphics::par("fin") #dev.size() MAY NOT BE EQUAL IN RSTUDIO: https://github.com/rstudio/rstudio/issues/10723 } else { if (is.character(vp)) seekViewport(vp) else pushViewport(vp) devsize = c(grid::convertWidth(grid::unit(1, "npc"), unitTo = "inch", valueOnly = TRUE), @@ -23,7 +23,7 @@ prepreprocess_meta = function(o, vp) { } - lin = par("cin")[2]# * scale + lin = graphics::par("cin")[2]# * scale lineH = lin / devsize[2] * scale lineW = lin / devsize[1] * scale diff --git a/R/tmapGridAux.R b/R/tmapGridAux.R index 16c172c4..c5a40a05 100644 --- a/R/tmapGridAux.R +++ b/R/tmapGridAux.R @@ -165,7 +165,7 @@ tmapGridGridPrep = function(a, bs, id, o) { bbx_orig <- bbx bbx <- suppressWarnings(bb(bbx, current.projection = crs_bb, projection = crs)) } - sasp = tmap:::get_asp_ratio(bbx) + sasp = get_asp_ratio(bbx) ## automatically determine number of grid lines if (is.na(n.x) && !is.na(n.y)) { diff --git a/R/tmapGridComp_leg_landscape.R b/R/tmapGridComp_leg_landscape.R index 6cbb53ac..d6476bac 100644 --- a/R/tmapGridComp_leg_landscape.R +++ b/R/tmapGridComp_leg_landscape.R @@ -262,10 +262,10 @@ tmapGridLegPlot.tm_legend_standard_landscape = function(comp, o, fH, fW) { if (vary_fill) { cols = unlist(fill_list)[id1:(10*(nlev2-1) + id2)] - cols_alph = paste0(cols, tmap::num_to_hex(gp$fill_alpha[1] * 255)) + cols_alph = paste0(cols, num_to_hex(gp$fill_alpha[1] * 255)) } else { alph = unlist(alpha_list)[id1:(10*(nlev2-1) + id2)] - cols_alph = paste0(col2hex(gp$fill[1]), tmap::num_to_hex(alph * 255)) + cols_alph = paste0(col2hex(gp$fill[1]), num_to_hex(alph * 255)) } grItems1 = list(gridCell(6, comp$item_ids[lvs], grid::rectGrob(x = x1 + 0.5*w, width= w, gp=gpar(fill = grid::linearGradient(colours = cols_alph), col = NA)))) } else { diff --git a/R/tmapGridComp_leg_portrait.R b/R/tmapGridComp_leg_portrait.R index f604cb1b..fc8a2056 100644 --- a/R/tmapGridComp_leg_portrait.R +++ b/R/tmapGridComp_leg_portrait.R @@ -432,10 +432,10 @@ tmapGridLegPlot.tm_legend_standard_portrait = function(comp, o, fH, fW) { if (vary_fill) { cols = unlist(fill_list)[id1:(10*(nlev2-1) + id2)] - cols_alph = paste0(cols, tmap::num_to_hex(gp$fill_alpha[1] * 255)) + cols_alph = paste0(cols, num_to_hex(gp$fill_alpha[1] * 255)) } else { alph = unlist(alpha_list)[id1:(10*(nlev2-1) + id2)] - cols_alph = paste0(col2hex(gp$fill[1]), tmap::num_to_hex(alph * 255)) + cols_alph = paste0(col2hex(gp$fill[1]), num_to_hex(alph * 255)) } grItems1 = list(gridCell(comp$item_ids[lvs], 3, grid::rectGrob(y = y2 + 0.5*h, height= h, gp=gpar(fill = grid::linearGradient(colours = rev(cols_alph)), col = NA)))) } else { diff --git a/R/tmapLeafletInit.R b/R/tmapLeafletInit.R index e3ec68ca..9d9e6d60 100644 --- a/R/tmapLeafletInit.R +++ b/R/tmapLeafletInit.R @@ -154,7 +154,7 @@ tmapLeafletAux = function(o, q) { lapply(lfp, function(lf) { if (length(pids)) for (pid in pids) lf = leaflet::addMapPane(lf, q$pane[pid], zIndex = q$lid2[pid] + 400) if (length(groups_radio) > 0L || length(groups_check) > 0L) { - lf = leaflet::addLayersControl(lf, baseGroups = groups_radio, overlayGroups = groups_check, position = tmap:::leaflet_pos(str2pos(o$control.position)), options = leaflet::layersControlOptions(collapsed = o$control.collapse)) + lf = leaflet::addLayersControl(lf, baseGroups = groups_radio, overlayGroups = groups_check, position = leaflet_pos(str2pos(o$control.position)), options = leaflet::layersControlOptions(collapsed = o$control.collapse)) } else { lf } diff --git a/R/tmap_arrange.R b/R/tmap_arrange.R index cc050954..b798339f 100644 --- a/R/tmap_arrange.R +++ b/R/tmap_arrange.R @@ -70,7 +70,7 @@ print_tmap_arrange <- function(tms, knit = FALSE, show = TRUE, add.titles = TRUE #tmp <- tempfile(fileext = ".png") #png( tmp, width=700, height=700, res = 100) - curdev <- dev.cur() + curdev <- grDevices::dev.cur() rmc = tmap_options(raster.max.cells = 36) tasps <- suppressMessages({ vapply(tms, function(tm) { @@ -81,7 +81,7 @@ print_tmap_arrange <- function(tms, knit = FALSE, show = TRUE, add.titles = TRUE }, numeric(1)) }) - dev.set(curdev) + grDevices::dev.set(curdev) tmap_options(rmc) #dev.off() diff --git a/R/tmap_save.R b/R/tmap_save.R index a6d0ec77..ed37a358 100644 --- a/R/tmap_save.R +++ b/R/tmap_save.R @@ -193,7 +193,7 @@ tmap_save = function(tm=NULL, filename=NA, device=NULL, width=NA, height=NA, uni if (!is.arrange && !missing(insets_tm) && !missing(insets_vp)) { args_inset = if (!is.na(scale)) list(scale = scale) else list() - if (class(insets_tm)=="list" && class(insets_vp)=="list") { + if (is(insets_tm, "list") && is(insets_vp, "list")) { if (length(insets_tm) != length(insets_vp)) stop("Number of insets unequal to number of viewports") mapply(function(tm_i, vp_i) { print(tm_i + do.call("tm_layout", args_inset), vp=vp_i) diff --git a/examples/tm_layout.R b/examples/tm_layout.R index e80bd26e..6c4a7b01 100644 --- a/examples/tm_layout.R +++ b/examples/tm_layout.R @@ -1,20 +1,24 @@ data(land, World) - tm_shape(land) + - tm_raster("elevation", - col.scale = tm_scale_intervals(breaks = c(-Inf, 250, 500, 1000, - 1500, 2000, 2500, 3000, 4000, Inf), - values = terrain.colors(9), midpoint = NA), - col.legend = tm_legend(title = "Elevation", position = tm_pos_in("left", "bottom"), - frame = TRUE, bg.color = "lightblue")) + - tm_shape(World, is.main = TRUE, crs = "+proj=eck4") + - tm_borders("grey20") + - tm_graticules(labels.size = .5) + - tm_text("name", size="AREA") + - #tm_compass(position = c(.65, .15), color.light = "grey90") + - #tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) + - tm_style("classic_v3") + - tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0)) + tm_raster( + "elevation", + col.scale = tm_scale_intervals( + breaks = c(-Inf, 250, 500, 1000, 1500, 2000, 2500, 3000, 4000, Inf), + values = terrain.colors(9), midpoint = NA + ), + col.legend = tm_legend( + title = "Elevation", position = tm_pos_in("left", "bottom"), + frame = TRUE, bg.color = "lightblue" + ) + ) + + tm_shape(World, is.main = TRUE, crs = "+proj=eck4") + + tm_borders("grey20") + + tm_graticules(labels.size = .5) + + tm_text("name", size = "AREA") + + # tm_compass(position = c(.65, .15), color.light = "grey90") + + # tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) + + tm_style("classic_v3") + + tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0)) data(land, World) diff --git a/examples/tm_symbols.R b/examples/tm_symbols.R index 623b6000..63a7e65a 100644 --- a/examples/tm_symbols.R +++ b/examples/tm_symbols.R @@ -39,9 +39,16 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & origin_data <- NLD_prov %>% st_set_geometry(NULL) %>% - mutate(FID= factor(1:n())) %>% - select(FID, origin_native, origin_west, origin_non_west) %>% - gather(key=origin, value=perc, origin_native, origin_west, origin_non_west, factor_key=TRUE) + dplyr::mutate(FID= factor(1:dplyr::n())) %>% + dplyr::select(FID, origin_native, origin_west, origin_non_west) %>% + tidyr::pivot_longer( + cols = c(origin_native, origin_west, origin_non_west), + names_to = "origin", + values_to = "perc", + names_transform = as.factor + ) %>% + dplyr::arrange(origin, FID) %>% + as.data.frame() origin_cols <- get_brewer_pal("Dark2", 3) diff --git a/man/tm_layout.Rd b/man/tm_layout.Rd index 37d63918..adc90630 100644 --- a/man/tm_layout.Rd +++ b/man/tm_layout.Rd @@ -279,22 +279,26 @@ Set of tmap options that are directly related to the layout. } \examples{ data(land, World) - tm_shape(land) + - tm_raster("elevation", - col.scale = tm_scale_intervals(breaks = c(-Inf, 250, 500, 1000, - 1500, 2000, 2500, 3000, 4000, Inf), - values = terrain.colors(9), midpoint = NA), - col.legend = tm_legend(title = "Elevation", position = tm_pos_in("left", "bottom"), - frame = TRUE, bg.color = "lightblue")) + - tm_shape(World, is.main = TRUE, crs = "+proj=eck4") + - tm_borders("grey20") + - tm_graticules(labels.size = .5) + - tm_text("name", size="AREA") + - #tm_compass(position = c(.65, .15), color.light = "grey90") + - #tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) + - tm_style("classic_v3") + - tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0)) + tm_raster( + "elevation", + col.scale = tm_scale_intervals( + breaks = c(-Inf, 250, 500, 1000, 1500, 2000, 2500, 3000, 4000, Inf), + values = terrain.colors(9), midpoint = NA + ), + col.legend = tm_legend( + title = "Elevation", position = tm_pos_in("left", "bottom"), + frame = TRUE, bg.color = "lightblue" + ) + ) + + tm_shape(World, is.main = TRUE, crs = "+proj=eck4") + + tm_borders("grey20") + + tm_graticules(labels.size = .5) + + tm_text("name", size = "AREA") + + # tm_compass(position = c(.65, .15), color.light = "grey90") + + # tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) + + tm_style("classic_v3") + + tm_layout(bg.color = "lightblue", inner.margins = c(0, 0, .02, 0)) data(land, World) diff --git a/man/tm_symbols.Rd b/man/tm_symbols.Rd index 9e4a1cec..d4b6e1f9 100644 --- a/man/tm_symbols.Rd +++ b/man/tm_symbols.Rd @@ -214,9 +214,16 @@ if (require(ggplot2) && require(dplyr) && require(tidyr) && require(tmaptools) & origin_data <- NLD_prov \%>\% st_set_geometry(NULL) \%>\% - mutate(FID= factor(1:n())) \%>\% - select(FID, origin_native, origin_west, origin_non_west) \%>\% - gather(key=origin, value=perc, origin_native, origin_west, origin_non_west, factor_key=TRUE) + dplyr::mutate(FID= factor(1:dplyr::n())) \%>\% + dplyr::select(FID, origin_native, origin_west, origin_non_west) \%>\% + tidyr::pivot_longer( + cols = c(origin_native, origin_west, origin_non_west), + names_to = "origin", + values_to = "perc", + names_transform = as.factor + ) \%>\% + dplyr::arrange(origin, FID) \%>\% + as.data.frame() origin_cols <- get_brewer_pal("Dark2", 3)