Skip to content

Instantly share code, notes, and snippets.

@kopperud
Created January 3, 2019 06:32
Show Gist options
  • Save kopperud/ae8cca0c29927d1d51fe08fd74cdb90a to your computer and use it in GitHub Desktop.
Save kopperud/ae8cca0c29927d1d51fe08fd74cdb90a to your computer and use it in GitHub Desktop.
library(ape)
library(ggtree) ## Ggtree is on github, devtools::install_github("GuangchuangYu/ggtree")
library(ggplot2)
library(gridExtra)
## Random tree
set.seed(5)
phy <- rtree(15)
## No transformation
p1 <- ggtree(phy, ladderize = TRUE) + theme_tree2() + geom_tiplab() + ggtitle("No transform")
## Manipulate the plotting coordinates, square transform
p2 <- ggtree(phy, ladderize = TRUE) +
theme_tree2() +
geom_tiplab() + scale_x_continuous(labels = function(x) sqrt(x), breaks = seq(0, 4)^2) + ## Backtransform the axis labels, and add appropriate breaks
ggtitle("Square transform")
p2$data$x <- p2$data$x ^2
## Exponential instead
p3 <- ggtree(phy, ladderize = TRUE) +
theme_tree2() +
geom_tiplab() +
scale_x_continuous(labels = function(x) log(x), breaks = exp(seq(0, 4))) +
ggtitle("Exponential transform")
p3$data$x <- exp(p3$data$x)
grid.arrange(p1, p2, p3)
@GuangchuangYu
Copy link

how about something like:

p1 + scale_x_continuous(trans='log2')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment