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.

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().

Examples

# 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" ) )
#> <svg width="200" height="100"> #> <defs> #> <filter id="blur" width="200" height="100"> #> <feGaussianBlur in="SourceGraphic" stdDeviation="2"/> #> </filter> #> </defs> #> <ellipse cx="40" cy="40" rx="25" ry="15" fill="green" filter="url(#blur)"/> #> </svg>