Skip to content

Commit

Permalink
Temporarily reverted to ggplot::sec_axis(trans) argument for ggplot2 …
Browse files Browse the repository at this point in the history
…< 3.5.0. Will update when ggplot2 3.5.0 is released.
  • Loading branch information
tripartio committed Feb 13, 2024
1 parent 5ec9dd6 commit 6edb073
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,35 @@ plot_ale <- function(

plot <- plot +
scale_y_continuous(
sec.axis = if (utils::packageVersion('ggplot2') >= '3.5.0') {
sec_axis(
transform = ~ ., # do not change the scale
name = NULL, # no axis title
labels = sec_labels,
breaks = sec_breaks
)
} else {
# older versions of ggplot2::sec_axis() used trans argument instead of transform
sec_axis(
trans = ~ .,
sec.axis = sec_axis(
trans = ~ ., # ggplot2 will change argument to transform
name = NULL,
labels = sec_labels,
breaks = sec_breaks
)
}
)

# # Code to adjust after ggplot2 3.5.0
# plot <- plot +
# scale_y_continuous(
# sec.axis = if (utils::packageVersion('ggplot2') >= '3.5.0') {
# sec_axis(
# transform = ~ ., # do not change the scale
# name = NULL, # no axis title
# labels = sec_labels,
# breaks = sec_breaks
# )
# } else {
# # older versions of ggplot2::sec_axis() used trans argument instead of transform
# sec_axis(
# trans = ~ .,
# name = NULL,
# labels = sec_labels,
# breaks = sec_breaks
# )
# }
# )


# Differentiate numeric x (line chart) from categorical x (bar charts)
if (x_type == 'numeric') {
Expand Down

0 comments on commit 6edb073

Please sign in to comment.