kittenlee kittenlee - 3 months ago 16
R Question

ggplot transform y axis histogram

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,

Answer

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.