Title: | Get Silhouettes of Organisms from PhyloPic |
---|---|
Description: | Work with the PhyloPic Web Service (<http://api-docs.phylopic.org/v2/>) to fetch silhouette images of organisms. Includes functions for adding silhouettes to both base R plots and ggplot2 plots. |
Authors: | William Gearty [aut, cre] , Lewis A. Jones [aut] , Scott Chamberlain [aut] , David Miller [ctb] |
Maintainer: | William Gearty <[email protected]> |
License: | GPL (>= 3) |
Version: | 1.5.0.9000 |
Built: | 2024-11-18 05:56:08 UTC |
Source: | https://github.com/palaeoverse/rphylopic |
Specify existing images, taxonomic names, or PhyloPic uuids to add PhyloPic silhouettes as a separate layer to an existing ggplot plot.
add_phylopic( img = NULL, name = NULL, uuid = NULL, filter = NULL, x, y, ysize = deprecated(), height = NA, width = NA, alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, hjust = 0.5, vjust = 0.5, remove_background = TRUE, verbose = FALSE )
add_phylopic( img = NULL, name = NULL, uuid = NULL, filter = NULL, x, y, ysize = deprecated(), height = NA, width = NA, alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, hjust = 0.5, vjust = 0.5, remove_background = TRUE, verbose = FALSE )
img |
A Picture or png array object, e.g.,
from using |
name |
|
uuid |
|
filter |
|
x |
|
y |
|
ysize |
|
height |
|
width |
|
alpha |
|
color |
|
fill |
|
horizontal |
|
vertical |
|
angle |
|
hjust |
|
vjust |
|
remove_background |
|
verbose |
|
One (and only one) of img
, name
, or uuid
must be specified.
Use parameters x
, y
, and ysize
to place the silhouette at a specified
position on the plot. The aspect ratio of the silhouette will always be
maintained.
x
and/or y
may be vectors of numeric values if multiple silhouettes
should be plotted at once. In this case, any other arguments (except for
remove_background
) may also be vectors of values, which will be recycled
as necessary.
When specifying a horizontal and/or vertical flip and a rotation, the
flip(s) will always occur first. If you would like to customize this
behavior, you can flip and/or rotate the image within your own workflow
using flip_phylopic()
and rotate_phylopic()
.
Note that png array objects can only be rotated by multiples of 90 degrees. Also, outline colors do not currently work for png array objects.
## Not run: # Put a silhouette behind a plot based on a taxonomic name library(ggplot2) ggplot(iris) + add_phylopic(x = 6.1, y = 3.2, name = "Iris", alpha = 0.2) + geom_point(aes(x = Sepal.Length, y = Sepal.Width)) # Put a silhouette in several places based on UUID posx <- runif(10, 0, 10) posy <- runif(10, 0, 10) heights <- runif(10, 0.4, 2) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) alpha <- runif(10, 0.3, 1) p <- ggplot(data.frame(cat.x = posx, cat.y = posy), aes(cat.x, cat.y)) + geom_blank() + add_phylopic(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, height = heights, fill = fills, alpha = alpha, angle = angle, horizontal = hor, vertical = ver) p + ggtitle("R Cat Herd!!") ## End(Not run)
## Not run: # Put a silhouette behind a plot based on a taxonomic name library(ggplot2) ggplot(iris) + add_phylopic(x = 6.1, y = 3.2, name = "Iris", alpha = 0.2) + geom_point(aes(x = Sepal.Length, y = Sepal.Width)) # Put a silhouette in several places based on UUID posx <- runif(10, 0, 10) posy <- runif(10, 0, 10) heights <- runif(10, 0.4, 2) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) alpha <- runif(10, 0.3, 1) p <- ggplot(data.frame(cat.x = posx, cat.y = posy), aes(cat.x, cat.y)) + geom_blank() + add_phylopic(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, height = heights, fill = fills, alpha = alpha, angle = angle, horizontal = hor, vertical = ver) p + ggtitle("R Cat Herd!!") ## End(Not run)
Specify existing images, taxonomic names, or PhyloPic uuids to add PhyloPic
silhouettes on top of an existing base R plot (like points()
).
add_phylopic_base( img = NULL, name = NULL, uuid = NULL, filter = NULL, x = NULL, y = NULL, ysize = deprecated(), height = NULL, width = NULL, alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, hjust = 0.5, vjust = 0.5, remove_background = TRUE, verbose = FALSE )
add_phylopic_base( img = NULL, name = NULL, uuid = NULL, filter = NULL, x = NULL, y = NULL, ysize = deprecated(), height = NULL, width = NULL, alpha = 1, color = NA, fill = "black", horizontal = FALSE, vertical = FALSE, angle = 0, hjust = 0.5, vjust = 0.5, remove_background = TRUE, verbose = FALSE )
img |
A Picture or png array object, e.g.,
from using |
name |
|
uuid |
|
filter |
|
x |
|
y |
|
ysize |
|
height |
|
width |
|
alpha |
|
color |
|
fill |
|
horizontal |
|
vertical |
|
angle |
|
hjust |
|
vjust |
|
remove_background |
|
verbose |
|
One (and only one) of img
, name
, or uuid
must be specified.
Use parameters x
, y
, hjust
, and vjust
to place the silhouette at a
specified position on the plot. If height
and width
are both
unspecified, then the silhouette will be plotted to the full height and/or
width of the plot. The aspect ratio of Picture
objects will always be
maintained (even when a plot is resized). However, if the plot is resized
after plotting a silhouette, the absolute size and/or position of the
silhouette may change.
Any argument (except for remove_background
) may be a vector of values if
multiple silhouettes should be plotted. In this case, all other arguments
may also be vectors of values, which will be recycled as necessary to the
length of the longest vector argument.
When specifying a horizontal and/or vertical flip and a rotation, the
flip(s) will always occur first. If you would like to customize this
behavior, you can flip and/or rotate the image within your own workflow
using flip_phylopic()
and rotate_phylopic()
.
Note that png array objects can only be rotated by multiples of 90 degrees. Also, outline colors do not currently work for png array objects.
## Not run: # single image plot(1, 1, type = "n", main = "A cat") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = 1, y = 1, height = 0.4) # lots of images using a uuid posx <- runif(10, 0, 1) posy <- runif(10, 0, 1) size <- runif(10, 0.1, 0.3) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) plot(posx, posy, type = "n", main = "A cat herd") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, height = size, fill = fills, angle = angle, horizontal = hor, vertical = ver) # Example using a cat background cat <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9") # setup plot area plot(posx, posy, type = "n", main = "A cat herd, on top of a cat", xlim = c(0, 1), ylim = c(0, 1)) # plot background cat add_phylopic_base(img = cat, alpha = 0.2) # overlay smaller cats add_phylopic_base(img = cat, x = posx, y = posy, height = size, alpha = 0.8) ## End(Not run)
## Not run: # single image plot(1, 1, type = "n", main = "A cat") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = 1, y = 1, height = 0.4) # lots of images using a uuid posx <- runif(10, 0, 1) posy <- runif(10, 0, 1) size <- runif(10, 0.1, 0.3) angle <- runif(10, 0, 360) hor <- sample(c(TRUE, FALSE), 10, TRUE) ver <- sample(c(TRUE, FALSE), 10, TRUE) fills <- sample(c("black", "darkorange", "grey42", "white"), 10, replace = TRUE) plot(posx, posy, type = "n", main = "A cat herd") add_phylopic_base(uuid = "23cd6aa4-9587-4a2e-8e26-de42885004c9", x = posx, y = posy, height = size, fill = fills, angle = angle, horizontal = hor, vertical = ver) # Example using a cat background cat <- get_phylopic("23cd6aa4-9587-4a2e-8e26-de42885004c9") # setup plot area plot(posx, posy, type = "n", main = "A cat herd, on top of a cat", xlim = c(0, 1), ylim = c(0, 1)) # plot background cat add_phylopic_base(img = cat, alpha = 0.2) # overlay smaller cats add_phylopic_base(img = cat, x = posx, y = posy, height = size, alpha = 0.8) ## End(Not run)
Specify existing images, taxonomic names, or PhyloPic uuids to add PhyloPic
silhouettes as a legend to an existing base R plot (like legend()
).
add_phylopic_legend( x, y = NULL, legend, img = NULL, name = NULL, uuid = NULL, ysize = deprecated(), height = NULL, color = NA, fill = "black", ... )
add_phylopic_legend( x, y = NULL, legend, img = NULL, name = NULL, uuid = NULL, ysize = deprecated(), height = NULL, color = NA, fill = "black", ... )
x |
|
y |
|
legend |
|
img |
A Picture or png array object, e.g.,
from using |
name |
|
uuid |
|
ysize |
|
height |
|
color |
|
fill |
|
... |
Additional arguments passed to |
This function can be used to add PhyloPic silhouettes as a legend
to a base R plot. Arguments available in legend()
can be used and
passed via ...
. Note that not all arguments in legend()
are
compatible with add_phylopic_legend()
. These include arguments for
modifying lines (e.g. lty
, lwd
, seg.len
), points (e.g. pch
,
pt.lwd
), and shading (e.g. angle
and density
). This is due to
add_phylopic_legend()
using add_phylopic_base()
to generate the
legend symbols. However, arguments for adjusting the legend appearance
such as text (e.g. cex
), legend box (e.g. bg
), and color (e.g.
border
) are compatible.
# Get UUIDs uuids <- get_uuid(name = "Canis lupus", n = 2) # Generate empty plot plot(0:10, 0:10, type = "n", main = "Wolves") # Add data points add_phylopic_base(uuid = uuids, color = "black", fill = c("blue", "green"), x = c(2.5, 7.5), y = c(2.5, 7.5), height = 2) # Add legend add_phylopic_legend(uuid = uuids, height = 0.5, color = "black", fill = c("blue", "green"), x = "bottomright", legend = c("Wolf 1", "Wolf 2"), bg = "lightgrey")
# Get UUIDs uuids <- get_uuid(name = "Canis lupus", n = 2) # Generate empty plot plot(0:10, 0:10, type = "n", main = "Wolves") # Add data points add_phylopic_base(uuid = uuids, color = "black", fill = c("blue", "green"), x = c(2.5, 7.5), y = c(2.5, 7.5), height = 2) # Add legend add_phylopic_legend(uuid = uuids, height = 0.5, color = "black", fill = c("blue", "green"), x = "bottomright", legend = c("Wolf 1", "Wolf 2"), bg = "lightgrey")
This function provides a convenient way to browse PhyloPic for a given taxonomic name of uuid.
browse_phylopic(name = NULL, uuid = NULL)
browse_phylopic(name = NULL, uuid = NULL)
name |
|
uuid |
|
This function returns a PhyloPic url for an input name
or
uuid
and opens the user's default web browser at this url. If no
name
or uuid
is supplied, the base url of PhyloPic images
is returned and opened instead.
A character
vector of a valid PhyloPic url for the specified
name
or uuid
. If no name
or uuid
is supplied,
the base url of PhyloPic images is returned.
## Not run: url <- browse_phylopic(name = "Acropora cervicornis") ## End(Not run)
## Not run: url <- browse_phylopic(name = "Acropora cervicornis") ## End(Not run)
The picture can be a Picture or png array object,
e.g., from using get_phylopic()
.
flip_phylopic(img, horizontal = TRUE, vertical = FALSE)
flip_phylopic(img, horizontal = TRUE, vertical = FALSE)
img |
A Picture or png array object, e.g.,
from using |
horizontal |
|
vertical |
|
A Picture or png array object (matching
the type of img
)
Other transformations:
recolor_phylopic()
,
rotate_phylopic()
This geom acts like ggplot2::geom_point()
, except that the specified
silhouettes are used as points. Silhouettes can be specified by their name
,
uuid
, or image objects (img
).
geom_phylopic( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, remove_background = TRUE, verbose = FALSE, filter = NULL )
geom_phylopic( mapping = NULL, data = NULL, stat = "identity", position = "identity", ..., na.rm = FALSE, show.legend = FALSE, inherit.aes = TRUE, remove_background = TRUE, verbose = FALSE, filter = NULL )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
... |
Other arguments passed on to
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
remove_background |
|
verbose |
|
filter |
|
One (and only one) of the img
, name
, or uuid
aesthetics must
be specified. The img
aesthetic can be
Picture objects or png array objects, e.g.,
from using get_phylopic()
. Use the x
and y
aesthetics to place the
silhouettes at specified positions on the plot. The height
or width
aesthetic specifies the height or width, respectively, of the silhouettes
in the units of the y axis (only one is allowed). The aspect ratio of the
silhouettes will always be maintained. The hjust
and vjust
aesthetics
can be used to manage the justification of the silhouettes with respect to
the x
and y
coordinates.
The color
(default: NA), fill
(default: "black"), and alpha
(
default: 1) aesthetics can be used to change the outline color, fill color,
and transparency (outline and fill) of the silhouettes, respectively. If
color
is specified and fill
is NA color
will be used as the fill
color (for backwards compatibility). If "original" is specified for the
color
aesthetic, the original color of the silhouette outline will be
used (usually the same as "transparent"). If "original" is specified for
the fill
aesthetic, the original color of the silhouette body will be
used (usually the same as "black"). To remove the fill or outline, you can
set fill
or color
to "transparent", respectively.
The horizontal
and vertical
aesthetics can be used to flip the
silhouettes. The angle
aesthetic can be used to rotate the silhouettes.
When specifying a horizontal and/or vertical flip and a rotation, the
flip(s) will always occur first. If you would like to customize this
behavior, you can flip and/or rotate the image within your own workflow
using flip_phylopic()
and rotate_phylopic()
.
Note that png array objects can only be rotated by multiples of 90 degrees. Also, outline colors do not currently work for png array objects.
geom_phylopic understands the following aesthetics:
x (required)
y (required)
img or uuid or name (one, and only one, required)
height or width (optional, maximum of only one allowed)
color or colour
fill
alpha
horizontal
vertical
angle
hjust
vjust
Learn more about setting these aesthetics in add_phylopic()
.
## Not run: library(ggplot2) df <- data.frame(x = c(2, 4), y = c(10, 20), name = c("Felis silvestris catus", "Odobenus rosmarus")) ggplot(df) + geom_phylopic(aes(x = x, y = y, name = name), fill = "purple", height = 10) + facet_wrap(~name) + coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) ## End(Not run)
## Not run: library(ggplot2) df <- data.frame(x = c(2, 4), y = c(10, 20), name = c("Felis silvestris catus", "Odobenus rosmarus")) ggplot(df) + geom_phylopic(aes(x = x, y = y, name = name), fill = "purple", height = 10) + facet_wrap(~name) + coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) ## End(Not run)
This function provides a convenient way to obtain attribution data
for PhyloPic images via an image uuid returned by get_uuid()
.
get_attribution(uuid = NULL, img = NULL, text = FALSE, permalink = FALSE)
get_attribution(uuid = NULL, img = NULL, text = FALSE, permalink = FALSE)
uuid |
|
img |
A Picture or png array object from
|
text |
|
permalink |
|
This function returns image uuid
specific attribution data,
including: contributor name, contributor uuid, contributor contact,
image uuid, license, and license abbreviation. If text
is set to
TRUE
, a text paragraph with the contributor name, year of contribution,
and license type is printed and image attribution data is returned
invisibly (i.e. using invisible()
. If permalink
is set to TRUE
, a
permanent link (hosted by PhyloPic) will be
generated. This link can be used to view and share details about the
image silhouettes, including contributors and licenses.
A list
of PhyloPic attribution data for an image uuid
or
a text output of relevant attribution information.
## Not run: # Get valid uuid uuid <- get_uuid(name = "Acropora cervicornis") # Get attribution data for uuid attri <- get_attribution(uuid = uuid) # Get list of valid uuids uuids <- get_uuid(name = "Scleractinia", n = 5) # Get attribution data for uuids get_attribution(uuid = uuids, text = TRUE) # Get attribution data for uuids and create permalink get_attribution(uuid = uuids, text = TRUE, permalink = TRUE) ## End(Not run)
## Not run: # Get valid uuid uuid <- get_uuid(name = "Acropora cervicornis") # Get attribution data for uuid attri <- get_attribution(uuid = uuid) # Get list of valid uuids uuids <- get_uuid(name = "Scleractinia", n = 5) # Get attribution data for uuids get_attribution(uuid = uuids, text = TRUE) # Get attribution data for uuids and create permalink get_attribution(uuid = uuids, text = TRUE, permalink = TRUE) ## End(Not run)
This retrieves a PhyloPic silhouette as a vectorized or rasterized object.
get_phylopic(uuid = NULL, format = "vector", height = 512, preview = FALSE) ## S3 method for class 'Picture' print(x, ...) ## S3 method for class 'phylopic' print(x, ...)
get_phylopic(uuid = NULL, format = "vector", height = 512, preview = FALSE) ## S3 method for class 'Picture' print(x, ...) ## S3 method for class 'phylopic' print(x, ...)
uuid |
|
format |
|
height |
|
preview |
|
x |
A Picture or png array object, e.g.,
from using |
... |
Ignored |
The height
argument is ignored if the format
argument is not set
to "raster". If format
is "raster", the height
argument specifies the
height of the desired raster object. The width of this raster object will
be determined by the original aspect ratio of the silhouette. If a
pre-rendered raster exists with the desired dimensions, it will be
downloaded from PhyloPic. If not, the vector image from PhyloPic will be
used to render a raster object of the desired size.
If format
is "vector", a Picture object
is returned. If format
is "raster", a png array representing the
rasterized image is returned. Either way, the uuid and download url are
included as the "uuid" and "url" attributes, respectively.
## Not run: # uuid uuid <- "9fae30cd-fb59-4a81-a39c-e1826a35f612" # Get data for an image img_svg <- get_phylopic(uuid, format = "vector") # vector format img_png <- get_phylopic(uuid, format = "raster") # raster format ## End(Not run)
## Not run: # uuid uuid <- "9fae30cd-fb59-4a81-a39c-e1826a35f612" # Get data for an image img_svg <- get_phylopic(uuid, format = "vector") # vector format img_png <- get_phylopic(uuid, format = "raster") # raster format ## End(Not run)
This function provides a convenient way to obtain a valid uuid or image url for an input taxonomic name. As multiple silhouettes can exist for each species in PhyloPic, this function extracts the primary image.
get_uuid(name = NULL, img = NULL, n = 1, filter = NULL, url = FALSE)
get_uuid(name = NULL, img = NULL, n = 1, filter = NULL, url = FALSE)
name |
|
img |
A Picture or png array object from
|
n |
|
filter |
|
url |
|
This function returns uuid(s) or image url (svg) for an input
name
. If a specific image is desired, the user can make use of
pick_phylopic to visually select the desired uuid/url.
A character
vector of a valid PhyloPic uuid or svg image
url.
## Not run: uuid <- get_uuid(name = "Acropora cervicornis") uuid <- get_uuid(name = "Dinosauria", n = 5, url = TRUE) ## End(Not run)
## Not run: uuid <- get_uuid(name = "Acropora cervicornis") uuid <- get_uuid(name = "Dinosauria", n = 5, url = TRUE) ## End(Not run)
Specify existing images, taxonomic names, or PhyloPic uuids to use PhyloPic silhouettes as legend key glyphs in a ggplot plot.
phylopic_key_glyph(img = NULL, name = NULL, uuid = NULL)
phylopic_key_glyph(img = NULL, name = NULL, uuid = NULL)
img |
A Picture or png array object, e.g.,
from using |
name |
|
uuid |
|
One (and only one) of img
, name
, or uuid
must be specified.
This argument may also be a vector/list of valid values if multiple silhouettes should be used as key glyphs. In this case, the specified silhouettes will be used as ordered as key glyphs one by one, with recycling as necessary.
Note that the sizes of the silhouettes in the legend are currently
maximized based on the size of the key. This size can be modified using the
legend.key.size
argument in ggplot2::theme()
. Therefore, the
silhouettes will not reflect the size aesthetic, and this function should
not be used for size legends.
## Not run: library(ggplot2) df <- data.frame(x = c(2, 4), y = c(10, 20), name = c("Felis silvestris catus", "Odobenus rosmarus")) ggplot(df) + geom_phylopic(aes(x = x, y = y, name = name, color = name), size = 10, show.legend = TRUE, key_glyph = phylopic_key_glyph(name = c("Felis silvestris catus", "Odobenus rosmarus"))) + coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) ## End(Not run)
## Not run: library(ggplot2) df <- data.frame(x = c(2, 4), y = c(10, 20), name = c("Felis silvestris catus", "Odobenus rosmarus")) ggplot(df) + geom_phylopic(aes(x = x, y = y, name = name, color = name), size = 10, show.legend = TRUE, key_glyph = phylopic_key_glyph(name = c("Felis silvestris catus", "Odobenus rosmarus"))) + coord_cartesian(xlim = c(1,6), ylim = c(5, 30)) ## End(Not run)
This function provides a visually interactive way to pick an image and valid uuid for an input taxonomic name. As multiple silhouettes can exist for each organism in PhyloPic, this function is useful for choosing the right image/uuid for the user.
pick_phylopic( name = NULL, n = 5, uuid = NULL, view = 1, filter = NULL, auto = NULL )
pick_phylopic( name = NULL, n = 5, uuid = NULL, view = 1, filter = NULL, auto = NULL )
name |
|
n |
|
uuid |
|
view |
|
filter |
|
auto |
|
This function allows the user to visually select the desired image
from a pool of silhouettes available for the input name
.
Note that while the view
argument can be any positive integer,
weaker/older computers may have issues displaying very large numbers of
images at the same time (i.e. view
> 9). If no images are displayed in
your plotting environment, try decreasing the value of view
.
A Picture object is returned. The uuid of the selected image is saved as the "uuid" attribute of the returned object and is also printed to console.
## Not run: # Defaults pane layout img <- pick_phylopic(name = "Canis lupus", n = 5) # 3 x 3 pane layout img <- pick_phylopic(name = "Scleractinia", n = 9, view = 9) ## End(Not run)
## Not run: # Defaults pane layout img <- pick_phylopic(name = "Canis lupus", n = 5) # 3 x 3 pane layout img <- pick_phylopic(name = "Scleractinia", n = 9, view = 9) ## End(Not run)
Preview a raster or vector representation of a PhyloPic silhouette. This will plot the silhouette on a new page in your default plotting device.
## S3 method for class 'Picture' plot(x, ...) ## S3 method for class 'phylopic' plot(x, ...)
## S3 method for class 'Picture' plot(x, ...) ## S3 method for class 'phylopic' plot(x, ...)
x |
A Picture or png array object, e.g.,
from using |
... |
Other arguments passed on to |
Function to recolor and change alpha levels of a PhyloPic image.
recolor_phylopic( img, alpha = 1, color = NULL, fill = NULL, remove_background = TRUE )
recolor_phylopic( img, alpha = 1, color = NULL, fill = NULL, remove_background = TRUE )
img |
A Picture or png array object, e.g.,
from using |
alpha |
|
color |
|
fill |
|
remove_background |
|
Some PhyloPic silhouettes do not have a transparent background.
Consequently, when color is used with vectorized versions of these images,
the entire image–including the background–is recolored. Setting
remove_background
to TRUE
(the default) will remove any white parts of
the image (which should only be the background).
A Picture or png array object (matching
the type of img
)
Other transformations:
flip_phylopic()
,
rotate_phylopic()
This function takes a supplied taxonomic name, queries it via the specified external API, resolves the API's returned taxonomic ID to the PhyloPic taxonomic node database, then retrieves PhyloPic image uuids (or urls) for that node.
resolve_phylopic( name, api = "gbif.org", hierarchy = FALSE, max_ranks = 5, n = 1, filter = NULL, url = FALSE )
resolve_phylopic( name, api = "gbif.org", hierarchy = FALSE, max_ranks = 5, n = 1, filter = NULL, url = FALSE )
name |
|
api |
|
hierarchy |
|
max_ranks |
|
n |
|
filter |
|
url |
|
If hierarchy
is FALSE
, the specified name
is queried via the
specified api
. The matched id is then resolved to the matching taxonomic
node in the PhyloPic database. If hierarchy
is TRUE
, the full taxonomic
hierarchy for name
is retrieved from the specified api
, those taxonomic
names are subset to max_ranks
ranks (starting from the specified name
and ascending the hierarchy). Then each of those names is resolved to the
matching taxonomic node in the PhyloPic database (where possible). In
either case, get_uuid()
is then used to retrieve n
image UUID(s) for
each taxonomic name.
Note that while the names of the returned list are the taxonomic names as
reported by the specified api
, the PhyloPic images that are returned are
associated with whatever taxonomic node that taxonomic name resolves to in
the PhyloPic database. This means that, if hierarchy
is TRUE
, the same
images may be returned for multiple taxonomic names. Also, if a particular
taxonomic name does not resolve to any node in the PhyloPic database, no
images will be returned for that name.
The following APIs are available for querying (api
):
"eol.org": the Encyclopedia of Life
(note: hierarchy = TRUE
is not currently available for this API) ("eol"
is also allowed)
"gbif.org": the Global Biodiversity Information Facility ("gbif" is also allowed)
"marinespecies.org": the World Registor of Marine Species ("worms" is also allowed)
"opentreeoflife.org": the Open Tree of Life ("otol" is also allowed)
"paleobiodb.org": the Paleobiology Database ("pbdb" is also allowed)
A list
where each value is n
(or fewer) PhyloPic image uuids (or
urls if url = TRUE
) and each name is the taxonomic name as matched and
reported by the specified api
. If hierarchy
is FALSE
, the list has
length 1. If hierarchy
is TRUE
, the list has maximum length
max_ranks
.
## Not run: # get a uuid for a single name resolve_phylopic(name = "Canis lupus") # get uuids for the taxonomic hierarchy resolve_phylopic(name = "Velociraptor mongoliensis", api = "paleobiodb.org", hierarchy = TRUE, max_ranks = 3) ## End(Not run)
## Not run: # get a uuid for a single name resolve_phylopic(name = "Canis lupus") # get uuids for the taxonomic hierarchy resolve_phylopic(name = "Velociraptor mongoliensis", api = "paleobiodb.org", hierarchy = TRUE, max_ranks = 3) ## End(Not run)
The picture can be a Picture or png array object,
e.g., from using get_phylopic()
. Note that png array objects can only be
rotated by multiples of 90 degrees.
rotate_phylopic(img, angle = 90)
rotate_phylopic(img, angle = 90)
img |
A Picture or png array object, e.g.,
from using |
angle |
|
A Picture or png array object (matching
the type of img
)
Other transformations:
flip_phylopic()
,
recolor_phylopic()
save_phylopic
is a convenient function for saving a PhyloPic silhouette
fetched via get_phylopic
. Available formats for
saving are those available in the grDevices package (i.e. pdf, png, svg,
tiff, jpeg, and bmp).
save_phylopic(img = NULL, path = NULL, bg = "transparent", ...)
save_phylopic(img = NULL, path = NULL, bg = "transparent", ...)
img |
|
path |
|
bg |
|
... |
Additional arguments available for the called grDevices
function. The called function is determined by the file extension used in
|
This function can be used to save a PhyloPic image obtained via
the get_phylopic
or any object of class
Picture
from the grImport2 package. Any file format available in the
grDevices package can be used (i.e. pdf, png, svg, tiff, jpeg, and
bmp).
An image is saved. Nothing is returned to the R interface.
## Not run: # Get image data img <- get_phylopic("27356f15-3cf8-47e8-ab41-71c6260b2724") # Save file save_phylopic(img = img, path = "./phylopic.png", width = 500, height = 500) ## End(Not run)
## Not run: # Get image data img <- get_phylopic("27356f15-3cf8-47e8-ab41-71c6260b2724") # Save file save_phylopic(img = img, path = "./phylopic.png", width = 500, height = 500) ## End(Not run)
scale_height_continuous()
scales the height of silhouettes whereas
scale_width_continuous()
scales the height of silhouettes.
scale_height_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), transform = "identity", trans = lifecycle::deprecated(), guide = "none" ) scale_width_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), transform = "identity", trans = lifecycle::deprecated(), guide = "none" )
scale_height_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), transform = "identity", trans = lifecycle::deprecated(), guide = "none" ) scale_width_continuous( name = waiver(), breaks = waiver(), labels = waiver(), limits = NULL, range = c(1, 6), transform = "identity", trans = lifecycle::deprecated(), guide = "none" )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
labels |
One of:
|
limits |
One of:
|
range |
a numeric vector of length 2 that specifies the minimum and maximum size of the plotting symbol after transformation. |
transform |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
trans |
|
guide |
A function used to create a guide or its name. See
|