svglite
svglite copied to clipboard
Undefined `xlink` namespace is generated by the `svgstring` function
Using svglite v2.1.1, given the following code:
require(ggplot2)
require(svglite)
p <- ggplot(mtcars) +
geom_point(aes(x = disp, y = mpg, color = gear))
svg <- svgstring(fix_text_size = FALSE, standalone = FALSE)
plot(p)
invisible(dev.off())
s <- svg()
write(s, file="foo.svg")
When I open the SVG file "foo.svg" in the chrome browser, I get the error message:
error on line 108 at column 401: Namespace prefix xlink for href on image is not defined
Line 108 of the SVG contains:
<image width='17.28' height='86.40' x='672.30' y='239.58' preserveAspectRatio='none' xlink:href='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAEsCAYAAAAC UNnVAAAAmElEQVQ4ja2UQRLDMAgDd3hk/tnX5agcknFaCoa0vnkMCEnGsL12GQhDYDpPwoDrpBFlRDWi/9Wu6AHC9FkLYLrzlhD3oJ3mDvRHRYy7IC8A7bCK8gpWKYDzeQVArDcDyD2YAnSofZvzaOA6Q7Oahp/ dmRuVTQ0xU5TGP2o8Waool1obVuv1q8qP9xPvg633XlGLDtfIhNUBcBeA5ss0BXMAAAAASUVORK5CYII='/>
The SVG renders correctly if we define xlink
in the first line of the SVG file. That is, if we replace the current first line:
<svg class='svglite' width='720.00pt' height='576.00pt' viewBox='0 0 720.00 576.00'>
with
<svg class='svglite' width='720.00pt' height='576.00pt' viewBox='0 0 720.00 576.00' xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">