YuLab-SMU / ggtree

:christmas_tree:Visualization and annotation of phylogenetic trees
https://yulab-smu.top/contribution-tree-data/
834 stars 173 forks source link

image retrival from phylopic assumes image size #468

Open tiagonardi opened 2 years ago

tiagonardi commented 2 years ago

Hello,

The automatic download from Phylopic is very convenient but I found a small problem: ggtree (version 3.2.1) tries to download an image with a size of 256x172, even when an image of this size is not present. For examples:

library(ggtree)
library(ggimage)
library(dplyr)
# ggtree v3.2.1
# test tree
tree<-read.tree(text="((Tyrannosaurus,Caretta_caretta),Elephas_maximus);")
# retrieval from phylopic
d <- ggimage::phylopic_uid(tree$tip.label)
# visualisation
p <- ggtree(tree) %<+% d + 
  geom_tiplab(aes(image=uid), geom="phylopic", offset=4.5,size=.05) +
  geom_tiplab(aes(label=label), offset = .2) + xlim(NA,20)
plot(p)

I get the error "failed to download http://phylopic.org/assets/images/submissions/6e47a104-e62a-4901-81f7-fca2ecacdb0e.256.png (HTTP 404)" as the image doesn't exist (http://phylopic.org/image/6e47a104-e62a-4901-81f7-fca2ecacdb0e/ has other sizes). As a workaround I changed the value to download another image (http://phylopic.org/image/7c9ab182-175d-4f02-96d0-09c1e5212bff/) for the same taxon with the correct size:

# replace the value with a working link
d ["Elephas_maximus","uid"] = "7c9ab182-175d-4f02-96d0-09c1e5212bff"
p <- ggtree(tree) %<+% d + 
  geom_tiplab(aes(image=uid), geom="phylopic", offset=4.5,size=.05) +
  geom_tiplab(aes(label=label), offset = .2) + xlim(NA,20)
plot(p)

It's not a big deal, but maybe can be helpful to have an indication about the image size requirement in the treedata book.

xiangpin commented 2 years ago

The default image size is 0.05. I think this is about the Tip label truncated issue. You can also read the manual of geom_tiplab via ?geom_tiplab for more detail about this geom.

GuangchuangYu commented 2 years ago

@xiangpin the issue is located in https://github.com/GuangchuangYu/ggimage/blob/master/R/geom_phylopic.R#L39-L41, that we are not able to determine which size is available in phylopic in current implementation.