Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* Fix a bug in `stat_summary_bin()` where one more than the requested number of
bins would be created (@thomasp85, #3824)

* Fix issue in `sec_axis()` that would throw warnings in the absence of any
secondary breaks (@thomasp85, #4368)

* Fix a bug in `geom_abline()` that resulted in `intercept` not being subjected
to the transformation of the y scale (@thomasp85, #3741)

Expand Down
50 changes: 29 additions & 21 deletions R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,30 +213,38 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
range_info <- temp_scale$break_info()

# Map the break values back to their correct position on the primary scale
old_val <- lapply(range_info$major_source, function(x) which.min(abs(full_range - x)))
old_val <- old_range[unlist(old_val)]
old_val_trans <- scale$trans$transform(old_val)
if (!is.null(range_info$major_source)) {
old_val <- lapply(range_info$major_source, function(x) which.min(abs(full_range - x)))
old_val <- old_range[unlist(old_val)]
old_val_trans <- scale$trans$transform(old_val)

old_val_minor <- lapply(range_info$minor_source, function(x) which.min(abs(full_range - x)))
old_val_minor <- old_range[unlist(old_val_minor)]
old_val_minor_trans <- scale$trans$transform(old_val_minor)
# rescale values from 0 to 1
range_info$major[] <- round(
rescale(
scale$map(old_val_trans, range(old_val_trans)),
from = range
),
digits = 3
)
} else {
old_val_trans <- NULL
}

# rescale values from 0 to 1
range_info$major[] <- round(
rescale(
scale$map(old_val_trans, range(old_val_trans)),
from = range
),
digits = 3
)
if (!is.null(range_info$minor_source)) {
old_val_minor <- lapply(range_info$minor_source, function(x) which.min(abs(full_range - x)))
old_val_minor <- old_range[unlist(old_val_minor)]
old_val_minor_trans <- scale$trans$transform(old_val_minor)

range_info$minor[] <- round(
rescale(
scale$map(old_val_minor_trans, range(old_val_minor_trans)),
from = range
),
digits = 3
)
range_info$minor[] <- round(
rescale(
scale$map(old_val_minor_trans, range(old_val_minor_trans)),
from = range
),
digits = 3
)
} else {
old_val_minor_trans <- NULL
}
}

# The _source values should be in (primary) scale_transformed space,
Expand Down