diamonds-data
diamonds-data copied to clipboard
Error finding "cubroot function
Hi Solomon, Might sound silly but I'm not sure what am I missing here..
On evaluating:
q = ggplot( data=diamonds, aes(carat, price, colour=color)) +
geom_point(alpha = 0.5, size = .75, position="jitter") +
scale_colour_brewer(type = "div",
guide = guide_legend(title = NULL, reverse=T,
override.aes = list(alpha = 1))) +
scale_x_continuous(trans=cubroot_trans(), limits = c(0.2,3),
breaks = c(0.2, 0.5, 1, 2, 3)) +
scale_y_continuous(trans=log10_trans(), limits = c(350,15000),
breaks = c(350, 1000, 5000, 10000, 15000)) +
theme_bw() + theme(legend.key = element_blank()) +
ggtitle("Price (log10) by Cube-Root of Carat and Color")
I am getting:
Error in inherits(x, "trans") : could not find function "cubroot_trans"
I'm sorry have you defined any - log10_trans() and trans_new() functions anywhere? Was checking out the blog
yes?
I'm having this issue, too. Did Solomon define cubroot_trans() himself?
I found an implementation of the cuberoot_trans function here. Thanks @FrankRuns
Also, note that cubroot_trans != cuberoot_trans... there is a typo!
cuberoot_trans = function() trans_new('cuberoot', transform = function(x) x^(1/3), inverse = function(x) x^3)
library('scales') #import the library
transformfunc = function(x) {x^(1/3)} #create the transformation function inversefunc = function(x) {x^3} #create the inverse function
#Create the transforming function that makes use of "trans_new" the above library 'scales' must be called first. cuberoot_trans = function () { trans_new('cuberoot', transform = transformfunc, #this references the function created above inverse = inversefunc) #this references the function created above }
ggplot(data = diamonds,mapping = aes(x=carat,y=price)) + geom_jitter() + scale_x_continuous(trans = cuberoot_trans(),breaks = c(0.2,0.5,1,2,3)) + #use own built transformation scale_y_log10() + #use built-in transformation coord_cartesian(xlim = c(0.2,3),ylim = c(350,15000))
Did you mean : '<-' instead of '=' in your example ? transformfunc = function(x) {x^(1/3)} #create the transformation function inversefunc = function(x) {x^3} #create the inverse function