Short answer:
You need to add an expand=c(0,0) argument to both the scale_x_sqrt and
scale_y_sqrt calls.
Long answer:
This was tricky. My first few (standard) answers for this (use
expand_limits(x=0, y=0) or setting the limits in the scale call) didn't
work. I decided it has to do with the scale sqrt transformation because
it worked fine with aes(x=sqrt(x), y=sqrt(y)).
By this point, I was using a different test data set:
tdta <- data.frame(x = seq(0,2,by=0.1),
y = seq(0,2,by=0.1))
I finally figured out that what was happening was that when the scale
was expanded (by default, the scale is expanded by 5% of the range in
each direction to give some padding between the extreme data/labels and
the edge of the plot), this was giving a negative number which was then
being inverted back to a positive number (greater than 0) which then put
the 0 break outside the limits.
library("scales")
# specifying limits of 0 to 2
sqrt(c(0,2))
expand_range(sqrt(c(0,2)), 0.05, 0)
# new limits after expanding and transforming back; now excludes 0
expand_range(sqrt(c(0,2)), 0.05, 0)^2
In the transformed space, negative numbers have no meaning and they
should not be being mapped to just their square. Mapping them all to
zero solves this problem, but requires creating a new transformation.
library("scales")
mysqrt_trans <- function() {
trans_new("mysqrt",
transform = base::sqrt,
inverse = function(x) ifelse(x<0, 0, x^2),
domain = c(0, Inf))
}
Then you can specify this transformation be used with
ggplot(data=tdta, aes(x=x, y=y)) +
geom_point() +
scale_x_continuous(trans="mysqrt") +
scale_y_continuous(trans="mysqrt")
which gives a nicer looking graph with the expected padding and breaks
and 0 shows up as a break.
> Thanks!
>
> Woody Setzer
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University