# packages
library(rphylopic)
library(ggplot2)
library(palmerpenguins)
library(dplyr)
## Basic plot
%>%
penguins filter(species %in% c('Adelie', 'Gentoo')) %>%
ggplot(aes(x=body_mass_g, y=bill_length_mm, color=species))+
geom_point(alpha=0.6)+
geom_smooth(method = "lm", se = FALSE) +
scale_color_manual(values = c("#6495ED", "#FFA54F"))+
xlab('Body mass (g)')+
ylab('Bill length (mm)')+
theme_classic()+
theme(legend.position = 'top',
legend.title = element_blank(),
legend.text = element_text(size=14),
axis.text = element_text(size=14),
axis.title = element_text(size=16)) -> plot1
plot1
The rphylopic package
I explained a little of what phylopic and the rphylopic package are here. I wanted to continue this series with explaining how to use this versatile package but this time creating a workflow to include the attribution of several silhouettes in the caption of a figure created using ggplot2.
The problem
The rphylopic package has a function to retrieve the attribution information from a silhouette: get_attribution(uuid=uuid)
. However, if you have several silhouettes you might want to automate the code to retrieve all the attributions in one step instead of for each silhouette. I came up with this workflow, which I hope will be useful to some:
Base plot using ggplot2
Let’s start by creating a simple plot to use as an example.
Now we add the silhouettes to the plot
Now that we have the basic plot let’s work on finding out which silhouettes we want to use. Sometimes a species may have more than one silhouette so we have to identify which specific silhouette we want and retrieve that specific uuid.
The species
## Let's get the uuid numbers for our species of interest
<- c('Pygoscelis papua')
gentoo <- c('Pygoscelis adeliae')
adelie
# For example, the gentoo penguin has two silhouettes, let's select the
# second one. Notice that you have to make the selection in the console.
# The silhouettes appear in the plots panel.
#pick_phylopic(gentoo) # 2 silhouettes
#pick_phylopic(adelie) # 1 silhouette
# Now let's get the uuid for each species, notice that we have to
# indicate the number of available silhouettes using n and
# the one we choose using square brackets
<- get_uuid('Pygoscelis papua', n=2)[2]
gp <- get_uuid('Pygoscelis adeliae')
ap
## Let's put the silhouettes that we will use in the environment
<- get_phylopic(gp)
gent <- get_phylopic(ap)
adel
## Now we add the silhouettes to our basic plot
+
plot1add_phylopic(img = gent, x=3000, y=42, ysize=3)+
add_phylopic(img = adel, x=6200, y=55, ysize = 3)->plot1
plot1
Cite rphylopic in your manuscript or work:
citation('rphylopic')
To cite rphylopic in publications, use the following citation:
Gearty, W. and Jones, L.A. 2023. rphylopic: An R package for
fetching, transforming, and visualising PhyloPic silhouettes. Methods
in Ecology and Evolution, 14(11), 2700-2708. doi:
10.1111/2041-210X.14221.
A BibTeX entry for LaTeX users is
@Article{,
title = {rphylopic: An R package for fetching, transforming, and visualising PhyloPic silhouettes},
author = {William Gearty and Lewis A. Jones},
year = {2023},
volume = {14},
number = {11},
pages = {2700-2708},
journal = {Methods in Ecology and Evolution},
doi = {10.1111/2041-210X.14221},
}
And that’s it, that’s all I have for you. If you have any questions don’t hesitate to contact me.
Gabby