Line ELement

library(easySVG)

line.1 <- line.svg(x1 = 50, y1 = 20, x2 = 150, y2 = 20)
message(line.1)
#> <line x1="50" y1="20" x2="150" y2="20" />

line.2 <- line.svg(x1 = 50, y1 = 40, x2 = 150, y2 = 40, stroke = "red", stroke.width = 3)
message(line.2)
#> <line x1="50" y1="40" x2="150" y2="40" style="stroke:red;stroke-width:3;"/>

Rect ELement

rect.1 <- rect.svg(x = 50, y = 60, width = 100, height = 10, fill = "blue")
message(rect.1)
#> <rect x="50" y="60" width="100" height="10"   style="fill:blue;"/>

rect.2 <- rect.svg(x = 50, y = 80, width = 100, height = 5, fill = "yellow", stroke = "none")
message(rect.2)
#> <rect x="50" y="80" width="100" height="5"   style="fill:yellow;stroke:none;"/>

Circle ELement

circle.1 <- circle.svg(cx = 80, cy = 100, r = 10, fill = "blue")
message(circle.1)
#> <circle cx="80" cy="100" r="10" style="fill:blue;" />

circle.2 <- circle.svg(cx = 120, cy = 100, r = 5, fill = "red", stroke = "none")
message(circle.2)
#> <circle cx="120" cy="100" r="5" style="fill:red;stroke:none;" />

Ellipse ELement

ellipse.1 <- ellipse.svg(cx = 100, cy = 120, rx = 20, ry = 5, fill = "blue")
message(ellipse.1)
#> <ellipse cx="100" cy="120" rx="20" ry="5" style="fill:blue;" />

Polygon ELement

points <- matrix(c( 50, 100, 120, 140, 135, 145), nrow = 3, ncol = 2)

polygon.1 <- polygon.svg(points = points, fill = "green", stroke = "none")
message(polygon.1)
#> <polygon points="50,140 100,135 120,145" style="fill:green;stroke:none;" />

Polyline ELement

points <- matrix(c( 50, 100, 120, 160, 155, 165), nrow = 3, ncol = 2)

polyline.1 <- polyline.svg(points = points)
message(polyline.1)
#> <polyline points="50 160 , 100 155 , 120 165"  />

Text ELement

text <- c("line.1", "line.2", "rect.1","rect.2",
          "circle.1 - circle.2", "ellipse.1",
          "polygon.1", "polyline.1")

text.elements <- lapply(1:length(text), 
                        function(x) get.text.svg(x = 10, y = 20*x, text.content = text[x], font.size = 6))

text.elements <- unlist(text.elements)

Output SVG

content <- list(line.1, line.2, rect.1, rect.2,
                circle.1, circle.2, ellipse.1,
                polygon.1, polyline.1, text.elements)
svg.name <- paste0(tempfile(),".svg")
pack.svg(width = 200, height = 200, pack.content = unlist(content), output.svg.name = svg.name)