-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
This is a documentation clarification request (or perhaps it is a bug report). The documentation for scale_continuous says that the breaks argument can take "a function that takes the limits as input and returns breaks as output". With some experimentation, I determined that the input is the limits after expansion and not what gets passed to the limits argument. If this is the intended behavior (reasonable given that having empty bands with no breaks around the data looks weird), it should probably be clear. My attempt to learn how to contribute on GitHub for the last hour did not get far, but here is my recommended wording: "A function that takes the limits (after expansion as specified by expand) as input and returns breaks as output"
To make it obvious what I mean,
library(tidyverse)
# Data
dt = tibble(
x = 1:6,
y = rnorm(x)
)
# Function that seems to "take the limits as input and return breaks as output"
BreakFunc = function(lim) seq(lim[1], lim[2], 2)
# I expect the plot to have horizontal axis breaks at seq(0, 7, 2) but it does not
ggplot(dt, aes(x=x, y=y))+
geom_point() +
scale_x_continuous(
limits = c(0, 7),
breaks = BreakFunc)# Explicitly setting the expand argument gets the expected plot
ggplot(dt, aes(x=x, y=y))+
geom_point() +
scale_x_continuous(
limits = c(0, 7),
breaks = BreakFunc,
expand = expand_scale(mult = 0, add = 0))
