If we have two numbers, A and B, the fold change from A to B is just B/A
a <- 10
b <- 100
fc <- b/a
fc
## [1] 10
In this example, fold change is 10 because B is 10 times A.
When B is bigger than A, fold change is greater than one. When A is bigger than B, fold change is less than one
a <- 1:10
b <- 10:1
fc <- b/a
df <- data.frame(a, b, fc, a.greaterthan.b = a > b)
df
## a b fc a.greaterthan.b
## 1 1 10 10.0000 FALSE
## 2 2 9 4.5000 FALSE
## 3 3 8 2.6667 FALSE
## 4 4 7 1.7500 FALSE
## 5 5 6 1.2000 FALSE
## 6 6 5 0.8333 TRUE
## 7 7 4 0.5714 TRUE
## 8 8 3 0.3750 TRUE
## 9 9 2 0.2222 TRUE
## 10 10 1 0.1000 TRUE
This compresses the information when A is bigger than B, making it hard to see both high and low fold changes on a plot:
ggplot(df, aes(a, fc, colour = a.greaterthan.b), size = 8) + geom_point()
If we use log2(fold change), fold changes lower than 1 (when B > A) become negative, while those greater than 1 (A > B) become positive. Now the values are symmetrical and it's easier to see fold changes in both directions on one plot.
log2fc <- log2(fc)
ggplot(df, aes(a, log2fc, colour = a.greaterthan.b), size = 8) + geom_point()
We can see explicitly that fold changes < 1 become negative and those > 1 become positive:
ggplot(df, aes(fc, log2fc, colour = a.greaterthan.b), size = 8) + geom_point()
It's also useful to know that a log2 fold change (B/A) of 1 means B is twice as large as A, while log2fc of 2 means B is 4x as large as A. Conversely, -1 means A is twice as large as B, and -2 means A is 4x as large as B.