Filling a circle with patterns in R using MikeFC's svgparser and minisvg

23 views Asked by At

I can't replicate the result of filling the circle with the pattern object. It will only draw a circle with no pattern inside it. I am following MikeFC's instructions found here: text The entirety of his code is down below:

library(grid)
library(svgparser)
# remotes::install_github('coolbutuseless/minisvg')
library(minisvg)

# Create SVG document
svg <- minisvg::svg_doc(width = 100, height = 100, fill = "#ECD078")
svg$rect(x = 20, y = 20, width = 60, height = 60, fill = "#542437", stroke = "grey70", stroke_width = 10)
svg$rect(x = 5, y = 5, width = 40, height = 40, opacity = 0.8, rx = "20%")
svg$rect(x = 55, y = 5, width = 40, height = 40, opacity = 0.8, rx = "20%")
svg$rect(x = 5, y = 55, width = 40, height = 40, opacity = 0.8, rx = "20%")
svg$rect(x = 55, y = 55, width = 40, height = 40, opacity = 0.8, rx = "20%")

# Convert SVG document to a grid graphics object i.e. a 'grob'
g <- read_svg(svg$as_character())
grid.newpage()
grid.draw(g)

g$vp <- viewport(width = unit(2, "cm"), height = unit(2, "cm"))
pat <- grid::pattern(g, width = unit(2, "cm"), height = unit(2, "cm"), extend = "repeat")

canvas <- circleGrob(r = unit(0.5, "npc"), gp = gpar(fill = pat))
grid.newpage()
grid.draw(canvas)

I was able to progress up to the turning the SVG document into a graphics object.square graphics object When I am trying to use that graphics object as a fill for a circle object and draw that circle object, it will only draw the circle but it will not apply the fill.circle object but fill somehow not applied

0

There are 0 answers