svg_image: Addition of an 'image' element

Description Usage Arguments Value Examples

View source: R/elements.R

Description

The svg_image() function adds an image to an svg object. The starting position is defined by x and y values. The image width and height are also required. All of these attributes are expressed in units of px.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
svg_image(
  svg,
  x,
  y,
  image,
  width = NULL,
  height = NULL,
  preserve_aspect_ratio = NULL,
  opacity = NULL,
  attrs = list(),
  anims = list(),
  filters = list(),
  id = NULL
)

Arguments

svg

The svg object that is created using the SVG() function.

x, y

The x and y positions of the upper left of the image to be included. The x and y values are relative to upper left of the SVG drawing area itself.

image

The URL for the image file.

width, height

The width and height of the rectangle in which the image will be placed. If both are not provided, the image's original dimensions will be used. If one of these is provided, then the image will be scaled to the provided value with the aspect ratio intact. Providing both will result in the image placed in center of the rectangle with the aspect ratio preserved.

preserve_aspect_ratio

Controls how the aspect ratio of the image is preserved. Use "none" if the image's original aspect ratio should not be respected; this will fill the rectangle defined by width and height with the image (and this is only if both values are provided).

opacity

The opacity of the element. Must be a value in the range of 0 to 1.

attrs

A presentation attribute list. The helper function svg_attrs_pres() can help us easily generate this named list object. For the most part, the list's names are the presentation attribute names and the corresponding values are the matching attribute values.

anims

An animation directive list for the element. This should be structured using the anims() function.

filters

A filter directive list for the element. This is easily created by using a list of filter_*() functions (e.g., list(filter_gaussian_blur(2), filter_drop_shadow(2, 2))).

id

An optional ID value to give to the built tag. This is useful for modifying this element in a later function call or for interacting with CSS.

Value

An svg object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
if (interactive()) {

# Create an SVG with an SVG image
# (the R logo) contained within it
svg <-
  SVG(width = 300, height = 300) %>%
    svg_image(
      x = 20, y = 20,
      width = 100,
      height = 100,
      image = "https://www.r-project.org/logo/Rlogo.svg"
    )
}

omsvg documentation built on Feb. 10, 2021, 5:10 p.m.