Learn R Programming

rphylopic (version 0.3.0)

add_phylopic_base: Input an image and add to an existing plot made with base graphics

Description

Input an image and add to an existing plot made with base graphics

Usage

add_phylopic_base(
  img,
  x = NULL,
  y = NULL,
  ysize = NULL,
  alpha = 0.2,
  color = NULL
)

Arguments

img

A png object, e.g, from using image_data()

x

x value of the silhouette center. Ignored if y and ysize are not specified.

y

y value of the silhouette center. Ignored if x and ysize are not specified.

ysize

Height of the silhouette. The width is determined by the aspect ratio of the original image. Ignored if x and y are not specified.

alpha

A value between 0 and 1, specifying the opacity of the silhouette.

color

Color to plot the silhouette in.

Details

Use parameters x, y, and ysize to place the silhouette at a specified position on the plot. If all three of these parameters are unspecified, then the silhouette will be plotted to the full height and width of the plot.

Examples

Run this code
if (FALSE) {
# get a silhouette
cat <- image_data("23cd6aa4-9587-4a2e-8e26-de42885004c9", size = 128)[[1]]

# single image
plot(1, 1, type="n", main="A cat")
add_phylopic_base(cat, 1, 1, 0.2)

# lots of images
posx <- runif(50, 0, 1)
posy <- runif(50, 0, 1)
size <- runif(50, 0.01, 0.2)
plot(posx, posy, type="n", main="A cat herd")
for (i in 1:50) {
  add_phylopic_base(cat, posx[i], posy[i], size[i])
}

# Example using a cat background
# 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))
# get a higher-resolution cat
cat_hires <- image_data("23cd6aa4-9587-4a2e-8e26-de42885004c9", size = 512)[[1]]
# plot background cat
add_phylopic_base(cat_hires, 0.5, 0.5, 1, alpha=0.2)
# overlay smaller cats
for (i in 1:50) {
  add_phylopic_base(cat, posx[i], posy[i], size[i], alpha=.8)
}
}

Run the code above in your browser using DataLab