svg_filter: Build an SVG <filter>

Description Usage Arguments Value Examples

View source: R/filters.R

Description

The svg_filter() let's us create a named <filter> element that we can apply to any SVG elements (such as shapes). We can bundle one or more filter elements by supplying a list of filter_*() calls to the filters argument.

Usage

1
svg_filter(svg, id, width = NULL, height = NULL, filters = list())

Arguments

svg

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

id

The ID value to assign to the filter. This must be provided and it should be unique among all <filter> elements.

width, height

The lengths of width and height define the extent of the filter.

filters

A list of filter_*() function calls. Examples include filter_image() and filter_gaussian_blur().

Value

An svg object.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (interactive()) {

# Set up an `svg_filter()` (called
# `"blur"`) that has the blur effect
# (using the `filter_gaussian_blur()`
# function); have the ellipse element
# use the filter by referencing it
# by name via the `"filter"` attribute
SVG(width = 200, height = 100) %>%
  svg_filter(
    id = "blur",
    filters = list(
      filter_gaussian_blur(stdev = 2)
    )
  ) %>%
  svg_ellipse(
    x = 40, y = 40,
    width = 50, height = 30,
    attrs = svg_attrs_pres(
      fill = "green",
      filter = "blur"
    )
  )
}

rich-iannone/omsvg documentation built on March 11, 2021, 5:13 p.m.