I am looking for a way to create set break steps in the x-axis similar to the question posted here: Change axis breaks without defining sequence - ggplot
I noticed that the answer to that question only works because the data being plotted are named x and y in the global environment. ggplot does not appear to pass to the scales_x_continuous function the variables 'x' and 'y' defined in the aes call.
i.e. this works:
x <- 1:10
y <- 1:10
df <- data.frame(x, y)
f <- function(x) seq(min(x), max(x), by = 2)
ggplot(df, aes(x,y)) + geom_point() + scale_y_continuous(breaks = f)
But this produces the error: "...object 'x' not found"
rm(x, y) #to remove the objects x and y defined earlier
df <- data.frame("xvar" = 1:10, "yvar" = 1:10)
f <- function(x) seq(min(x), max(x), by = 2)
ggplot(df, aes(x,y)) + geom_point() + scale_y_continuous(breaks = f)
Is there a way to pass the variables defined in the aes part of the ggplot call and make the second bit of code work?