Skip to content

Commit

Permalink
tm_scale discrete and rank working
Browse files Browse the repository at this point in the history
  • Loading branch information
mtennekes committed Mar 13, 2024
1 parent d409dc1 commit ad3e758
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
5 changes: 4 additions & 1 deletion R/step2_helper_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ getdts = function(aes, unm, p, q, o, dt, shpvars, layer, mfun, args, plot.order)
# the condition has length > 1
# Calls: <Anonymous> ... with -> with.default -> eval -> eval -> apply_scale
# Detected in types of titles. # Example to illustrate the type of titles
if (all(is.ena(l$title))) l$title = paste0(names(v), attr(cls, "units"))
unit = if (!is.null(s$unit)) s$unit else ""
if (unit != "") unit = paste0(" (", unit, ")")

if (all(is.ena(l$title))) l$title = paste0(names(v), attr(cls, "units"), unit)
}


Expand Down
3 changes: 2 additions & 1 deletion R/tm_scale_.R
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ tm_scale_rank = function(n = NULL,
labels = NULL,
label.na = NA,
label.null = NA,
label.format = list()) {
label.format = list(),
unit = "rank") {
structure(c(list(FUN = "tmapScaleRank"), as.list(environment())), class = c("tm_scale_rank", "tm_scale", "list"))
}

Expand Down
6 changes: 3 additions & 3 deletions R/tmapChart.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ bin_num = function(x1, breaks_def, chart) {
if (is.null(chart$breaks)) {
if (!predefined) {
breaks = pretty(x1)
ids = 1L
ids = rep(1L, length(breaks) - 1)

} else {
breaks = breaks_def
Expand All @@ -117,10 +117,10 @@ bin_num = function(x1, breaks_def, chart) {

break_mids = (breaks[-1] + head(breaks, -1)) / 2

if (!is.null(breaks_def)) {
if (predefined) {
ids = as.integer(cut(break_mids, breaks_def, include.lowest = TRUE, right = FALSE))
} else {
ids = 1
ids = rep(1L, length(breaks) - 1)
}

}
Expand Down
14 changes: 11 additions & 3 deletions R/tmapScaleRank.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,23 @@ tmapScaleRank = function(x1, scale, legend, chart, o, aes, layer, layer_args, so
limits = limits
})
# NOTE: tr and limits are included in the output to facilitate the transformation of the leaflet continuous legend ticks (https://github.com/rstudio/leaflet/issues/665)
chartFun = paste0("tmapChart", toTitleCase(chart$summary))

chart = do.call(chartFun, list(chart,
bin_colors = NULL,
breaks_def = NULL,
na.show = na.show,
x1 = x1))


if (submit_legend) {
if (bypass_ord) {
format_aes_results(vals, legend = legend)
format_aes_results(vals, legend = legend, chart = chart)
} else {
format_aes_results(vals, ids, legend)
format_aes_results(vals, ids, legend, chart = chart)
}
} else {
list(vals = vals, ids = ids, legend = legend, bypass_ord = bypass_ord)
list(vals = vals, ids = ids, legend = legend, chart = chart, bypass_ord = bypass_ord)
}

})
Expand Down
3 changes: 2 additions & 1 deletion R/tmap_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@
outliers.trunc = c(FALSE, FALSE),
trans = "identity",
limits = list(fill = NA, col = NA, 0)),
rank = list(n = 5)), # NA means take data range, 0 means include 0
rank = list(n = 5,
unit = "rank")), # NA means take data range, 0 means include 0



Expand Down

0 comments on commit ad3e758

Please sign in to comment.