diamonds-data icon indicating copy to clipboard operation
diamonds-data copied to clipboard

Error finding "cubroot function

Open emptyr1 opened this issue 9 years ago • 6 comments

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"

emptyr1 avatar Feb 02 '16 04:02 emptyr1

I'm sorry have you defined any - log10_trans() and trans_new() functions anywhere? Was checking out the blog

emptyr1 avatar Feb 02 '16 04:02 emptyr1

yes?

emptyr1 avatar Feb 15 '16 17:02 emptyr1

I'm having this issue, too. Did Solomon define cubroot_trans() himself?

radlinsky avatar Jan 08 '17 18:01 radlinsky

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)

radlinsky avatar Jan 08 '17 18:01 radlinsky

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))

Indodayentsimbi avatar Feb 05 '18 18:02 Indodayentsimbi

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

DCiprut avatar May 12 '22 11:05 DCiprut