I am trying to create a squared transform for the y-axis using scales::trans_new but am hitting an error.
MWE
data = data.frame(x = 1:10, y = runif(10), z=rnorm(10, 10)) library(ggplot2) ggplot(data, aes(x, y, size=z)) + geom_point() + scale_y_continuous(trans=scales::trans_new("sq", function(x) x^2, function(x) x^(1/2))) gives the error
Error in if (zero_range(as.numeric(limits))) { :
missing value where TRUE/FALSE needed
I tries adding limits and domain but got the same error.
scale_y_continuous(trans=scales::trans_new("sq", function(x) x^2, function(x) x^(1/2)), limits=c(0,1)) scale_y_continuous(trans=scales::trans_new("sq", function(x) x^2, function(x) x^(1/2), domain=c(0,1)), limits=c(0,1)) It seesm to be the inverse argument that is causing the error - but all values of y are positive, so I don't understand. How can I do this please?
scale_y_continuous(trans = scales::trans_new("sq", function(x){x^2}, function(x){sqrt(abs(x))}))absworked. Dave2e has come to the same conclusion by the looks of it - but I thknk a slightly safer workaround. Thanks again for your help.