image
elementThe 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
.
svg_image(
svg,
x,
y,
image,
width = NULL,
height = NULL,
preserve_aspect_ratio = NULL,
opacity = NULL,
attrs = list(),
anims = list(),
filters = list(),
id = NULL
)
The svg
object that is created using the SVG()
function.
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.
The URL for the image file.
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.
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).
The opacity of the element. Must be a value in the
range of 0
to 1
.
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.
An animation directive list for the element. This should be
structured using the anims()
function.
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))
).
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.
An svg
object.
# NOT RUN {
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"
)
}
# }
Run the code above in your browser using DataLab