ggtree, ggimage : issue with radial rotation of external image files around circular phylogeny
0
0
Entering edit mode
@41d104b5
Last seen 11 days ago

Enter the body of text here

Code should be placed in three backticks as shown below


######## Issue with radial orientation of custom symbols on tree ########
# Problem: cannot change orientation of custom-made symbols at tips of a circular phylogeny
# I have up to 14 custom-made symbols to map onto the tips of a large tree. I need each symbol to be oriented radially.
# I have created a small reproducible example with colored squares. This requires downloading a folder of 6 .png image files hosted on my github page.

# Packages
library("ggtree") # v(2.0.4)
library("ggimage") # v(0.2.8)
library("ggplot2") # v(3.3.3)
# I am running R version 3.6.3 (2020-02-29)

# Create example tree
tree = read.tree(text = "((((Nigetia_formosalis, Abablemma_duomaculata), Arugisa_lutea), (Phytometra_rhodarialis, Hypsoropha_monilis)), Papilio_rutulus);")

# Create annotation vectors
trait1 <- c(rep("red.png", 6), rep(NA, 5))
trait2 <- c(rep("orange.png", 6), rep(NA, 5))
trait3 <- c(rep("yellow.png", 6), rep(NA, 5))
trait4 <- c(rep("green.png", 6), rep(NA, 5))
trait5 <- c(rep("blue.png", 6), rep(NA, 5))
trait6 <- c(rep("purple.png", 6), rep(NA, 5))

# Set directory to external folder of files
# 1) go to https://github.com/moria-robinson/ggtree-radial-image-orientation
# 2) download the six .png image files, each a colored square
# 3) set local path to location of these image files; this navigates to 'downloads' folder
setwd("~/Downloads")

# Create tree. Issue: symbols do not rotate. Goal is that each set of symbols is rotated radially (e.g. at each tip, symbols should look like they do for the species on the horizontal axis - Hypsoropha and Abablemma)
# - I show the different angle commands I tried in different rows
tree.out <- ggtree(tree, layout="circular") + 
  geom_tiplab(size=2, offset=0.25, color="black", align=TRUE) +
  geom_image(image=trait1, angle=0, nudge_x = 24, size=.02) +
  geom_image(image=trait2, angle=45, nudge_x = 28, size=.02) + 
  geom_image(image=trait3, angle=90, nudge_x = 32, size=.02) +
  geom_image(image=trait4, angle=90, nudge_x = 36, size=.02) +
  geom_image(image=trait5, angle=90, nudge_x = 40, size=.02) +
  geom_image(image=trait6, angle=90, nudge_x = 44, size=.02) +
  ggplot2::xlim(-35, 35)
tree.out # preview as a PDF 8 x 8

# Tree that is generated + desired output can be viewed here: [https://imgur.com/a/jC7fODA][1]

# This will save a PDF of the tree in the downloads folder
pdf("~/Downloads/tree.out.pdf", width=8, height=8)
tree.out
dev.off()

# I have followed the ggimage vignette, and also tried angle commands described in threads here (https://groups.google.com/g/bioc-ggtree/c/o35PV3iHO-0) and here (https://github.com/YuLab-SMU/ggtree/issues/17) (e.g. using angle=angle, or angle=angle+90 for radial orientation), but none change the symbol angle. Again, the goal is all radial orientation.
#     geom_image(aes(image=trait4, angle=angle), nudge_x = 36, size=.02) +
#     geom_image(image=trait5, aes(angle=angle), nudge_x = 40, size=.02) +
#     geom_image(image=trait6, angle="angle", nudge_x = 44, size=.02) +


sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggimage_0.2.8 ggplot2_3.3.3 ggtree_2.0.4 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6          pillar_1.4.7        compiler_3.6.3      BiocManager_1.30.15 tools_3.6.3         digest_0.6.27      
 [7] jsonlite_1.7.2      tidytree_0.3.4      lifecycle_0.2.0     tibble_3.0.6        nlme_3.1-144        gtable_0.3.0       
[13] lattice_0.20-38     pkgconfig_2.0.3     rlang_0.4.10        cli_2.2.0           ggplotify_0.0.7     DBI_1.1.1          
[19] rstudioapi_0.13     magick_2.7.2        rvcheck_0.1.8       parallel_3.6.3      xfun_0.21           treeio_1.10.0      
[25] withr_2.4.1         dplyr_1.0.3         gridGraphics_0.5-1  generics_0.1.0      vctrs_0.3.6         grid_3.6.3         
[31] tidyselect_1.1.0    glue_1.4.2          R6_2.5.0            fansi_0.4.2         farver_2.0.3        purrr_0.3.4        
[37] tidyr_1.1.2         magrittr_2.0.1      scales_1.1.1        ellipsis_0.3.1      assertthat_0.2.1    ape_5.4-1          
[43] colorspace_2.0-0    labeling_0.4.2      tinytex_0.29        lazyeval_0.2.2      munsell_0.5.0       crayon_1.3.4
ggimage ggtree • 124 views
ADD COMMENT

Login before adding your answer.

Traffic: 300 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6