|
17 | 17 | #' keep the default `NULL` argument. |
18 | 18 | #' @param negative.small When the scale limits include 0 or negative numbers, |
19 | 19 | #' what should be the smallest absolute value that is marked with a tick? |
| 20 | +#' If `NULL` (default), will be the smallest of 0.1 or 0.1 times the absolute |
| 21 | +#' scale maximum. |
20 | 22 | #' @param short.theme A theme [element][element_line()] for customising the |
21 | 23 | #' display of the shortest ticks. Must be a line or blank element, and |
22 | 24 | #' it inherits from the `axis.minor.ticks` setting for the relevant position. |
@@ -69,7 +71,7 @@ guide_axis_logticks <- function( |
69 | 71 | mid = 1.5, |
70 | 72 | short = 0.75, |
71 | 73 | prescale.base = NULL, |
72 | | - negative.small = 0.1, |
| 74 | + negative.small = NULL, |
73 | 75 | short.theme = element_line(), |
74 | 76 | expanded = TRUE, |
75 | 77 | cap = "none", |
@@ -186,40 +188,12 @@ GuideAxisLogticks <- ggproto( |
186 | 188 |
|
187 | 189 | # Reconstruct original range |
188 | 190 | limits <- transformation$inverse(scale$get_limits()) |
189 | | - has_negatives <- any(limits <= 0) |
190 | 191 |
|
191 | | - if (!has_negatives) { |
192 | | - start <- floor(log10(min(limits))) - 1L |
193 | | - end <- ceiling(log10(max(limits))) + 1L |
194 | | - } else { |
195 | | - params$negative_small <- params$negative_small %||% 0.1 |
196 | | - start <- floor(log10(abs(params$negative_small))) |
197 | | - end <- ceiling(log10(max(abs(limits)))) + 1L |
198 | | - } |
| 192 | + ticks <- minor_breaks_log(smallest = params$negative_small)(limits) |
| 193 | + tick_type <- match(attr(ticks, "detail"), c(10, 5, 1)) |
| 194 | + ticks <- transformation$transform(ticks) |
199 | 195 |
|
200 | | - # Calculate tick marks |
201 | | - tens <- 10^seq(start, end, by = 1) |
202 | | - fives <- tens * 5 |
203 | | - ones <- as.vector(outer(setdiff(2:9, 5), tens)) |
204 | | - |
205 | | - if (has_negatives) { |
206 | | - # Filter and mirror ticks around 0 |
207 | | - tens <- tens[tens >= params$negative_small] |
208 | | - tens <- c(tens, -tens, 0) |
209 | | - fives <- fives[fives >= params$negative_small] |
210 | | - fives <- c(fives, -fives) |
211 | | - ones <- ones[ones >= params$negative_small] |
212 | | - ones <- c(ones, -ones) |
213 | | - } |
214 | | - |
215 | | - # Set ticks back into transformed space |
216 | | - ticks <- transformation$transform(c(tens, fives, ones)) |
217 | | - nticks <- c(length(tens), length(fives), length(ones)) |
218 | | - |
219 | | - logkey <- data_frame0( |
220 | | - !!aesthetic := ticks, |
221 | | - .type = rep(1:3, times = nticks) |
222 | | - ) |
| 196 | + logkey <- data_frame0(!!aesthetic := ticks, .type = tick_type) |
223 | 197 |
|
224 | 198 | # Discard out-of-bounds ticks |
225 | 199 | range <- if (params$expanded) scale$continuous_range else scale$get_limits() |
|
0 commit comments