Closed willgearty closed 1 year ago
In creating this, I realized that the body of add_phylopic()
could basically be changed to:
annotate(rphylopic:::GeomPhylopic, ...)
I think this would make it pretty easy to vectorize it for #42.
Now supports polar coordinates (including the ggtree "circular" layout) as requested by @bschilder:
d <- data.table::fread("https://github.com/YuLab-SMU/ggtree/files/11001046/phylo_data.csv")
d <- as.data.frame(d) |> `rownames<-`(d$species)
tr <- rtree(nrow(d), tip.label = d$species)
ggtree(tr, layout = "circular") %<+% d +
geom_phylopic(aes(uuid=svg_uid), size = .1)
(I've reached out to PhyloPic about the silhouettes that are showing up as rectangles)
Amazing! Thanks @willgearty !
Regarding the rectangle issue, this comes from the fact that some images have a filled background and others have a transparent background.
While the ultimate solution would be to have consistency within the phylopic database, @xiangpin came up with a fix using magick
to remove the background on the fly:
https://github.com/GuangchuangYu/ggimage/pull/46
Thanks for pointing me to that PR @bschilder. Unfortunately, the default (and encouraged) functionality for rphylopic is to handle vector images (svgs), so magick::image_convert()
won't work in this case. However, I have added the option to use the "original" color for now.
Thanks for the thorough review @LewisAJones! I've fixed the handling of alpha values (now we just use recolor_phylopic
instead of doing some funky/buggy stuff within grid.picture
), fixed the handling of white backgrounds (https://github.com/keesey/phylopic/issues/14) which reduced the need for extra details about the color argument, and fixed a new bug related to highly nested svg objects (I think that may be my first recursive function that I've written in R).
Let me know what you think!
This PR adds a new
geom_phylopic()
which acts likegeom_point()
, but places PhyloPic silhouettes instead. The silhouettes can be specified with "name", "uuid", or actual image objects (svg or png).Note that the ggimage package also has a function called "geom_phylopic", but this function has several advantages:
I suppose we could call this something else, but I don't think there will be too much usage overlap.
In addition to the new function, I've also vectorized both
add_phylopic
(which usesggplot2::annotate
and the newGeomPhylopic
) andadd_phylopic_base
(which now usesmapply
to allow any argument to be vectorized).Fixes https://github.com/palaeoverse-community/rphylopic/issues/25 and Fixes https://github.com/palaeoverse-community/rphylopic/issues/42.