Reputation: 3
I have this line of code:
ggplot(data=AB2, aes(AB2$logbm)) +
geom_histogram(breaks=seq(-1.5, 2.5, by=((max(AB2$logbm)-min(AB2$logbm))/7)))
And I have problem in trying to transform the unit of y axis - first I need to log it, with:
scale_y_log10()
After that I want to divide all the values by 60
, then multiple by 1.25
. However with the above code, I dont seem to be able to adjust it with simply adding: 60*1.25
after the command.
Is there a way to tell ggplot
to do it??
Cheers,
Upvotes: 0
Views: 796
Reputation: 6372
You can also define your own trans
using the scales package. Normally:
scale_y_continuous(trans = "log10")
With transformation:
scale_y_continuous(trans = scales::trans_new("lognew",
transform = function(x){log10(x)*1.25/60},
inverse = function(x){10^(x*60/1.25)})
)
Upvotes: 3
Reputation: 9923
You can do this, though not sure why you would want to, by using ..count..
in the aes
ggplot(AB2, aes(x = logbm)) +
scale_y_log10() +
geom_histogram(aes(y = ..count.. * 1.25 / 60))
NB no need to reference the data.frame in the aes.
Upvotes: 2