ggtree icon indicating copy to clipboard operation
ggtree copied to clipboard

image retrival from phylopic assumes image size

Open tiagonardi opened this issue 3 years ago • 2 comments
trafficstars

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.

tiagonardi avatar Jan 10 '22 12:01 tiagonardi

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.

xiangpin avatar Jan 10 '22 12:01 xiangpin

@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.

GuangchuangYu avatar Jan 11 '22 05:01 GuangchuangYu