require(ggplot2)
require(dplyr)
require(tidyr)
cbPalette <- c("#999999", "#E69F00", "#56B4E9", "#009E73",
               "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

Important Basics on exponentials and logarithms

x <- seq(from = -2, to = 2, by = 0.1)
y <- exp(x)
y1 <- 2^x
y2 <- 10^x
df <- data.frame(x = x, exp = y, base_2 = y1, base_10 = y2)
df <- gather(df, Base, Value, -x)
ggplot(df, aes(x=x, y = Value, colour = Base)) + geom_vline(xintercept = 0, color = cbPalette[1]) + geom_line() + scale_colour_manual(values = cbPalette[2:4]) + ylim(0,5) + theme_bw(14) + ylab("Exponential") + xlab("'log'") + theme(panel.grid.minor = element_blank()) + theme(panel.background = element_rect(colour = cbPalette[1],size = 2))

So \(base^{0}\) is always 1, \(base^{1} = base\)

Some exponential rules

And for the logarithms

  • log of y to a base is the number x you have to power base with to get y.
  • so in the plot above, choose a y value, look what is the corresponding x value, it is the log(y) to the respective base (in the plot exp, 2, 10)
  • note for relative abundances, y is betwen 0 and 1, so the log(y) are from -Inf to 0.
    • log(1) is 0 independent of base
  • What if you have log to base e (as in R), but you want to base 2?
    • \(2^{3} = (e^{z})^3 = e^{z*3}\) with \(e^{z} = 2\) so \(z = log(2)\) so the log base e of 2.
      • that means \(log_{2}(y)\) is \(z\times log(y) = \frac{log(y)}{log(2)}\)
  • so general rule: log of y to the base x = log(y)/log(x)

all other rules come directly from the exponential rules:

  • take \(a = 2^{4}\) so log(a) = 4 (base 2) and \(b = 2^{3}\), so log(b) = 2
  • then rule 1: log(a*b) = log(a) + log(b) (think of base 2, \(2^{4}\times2^{3} = 2^{3+4}\) )
  • rule 2: \(log(\frac{a}{b}) = log(a) - log(b)\)
  • rule 3: \(log(a^{z}) = z*log(a)\)
x <- seq(from = 0, to = 1, by = 0.01)
y <- log(x)
df <- data.frame(x = x, log_x = y)
df$Base = "exp"
ggplot(df, aes(x=x, y = log_x, colour = Base)) + geom_vline(xintercept = 0, color = cbPalette[1]) + geom_line() + scale_colour_manual(values = cbPalette[2]) +  theme_bw(14) + ylab("log(x)") + theme(panel.grid.minor = element_blank()) + theme(panel.background = element_rect(colour = cbPalette[1],size = 2))