svgstring: Access current SVG as a string.

Description Usage Arguments Details Value Examples

View source: R/SVG.R

Description

This is a variation on svglite that makes it easy to access the current value as a string.

Usage

1
2
svgstring(width = 10, height = 8, bg = "white", pointsize = 12,
  standalone = TRUE, system_fonts = list(), user_fonts = list())

Arguments

width

Height and width in inches.

height

Height and width in inches.

bg

Default background color for the plot (defaults to "white").

pointsize

Default point size.

standalone

Produce a standalone svg file? If FALSE, omits xml header and default namespace.

system_fonts

Named list of font names to be aliased with fonts installed on your system. If unspecified, the R default families sans, serif, mono and symbol are aliased to the family returned by match_family().

user_fonts

Named list of fonts to be aliased with font files provided by the user rather than fonts properly installed on the system. The aliases can be fonts from the fontquiver package, strings containing a path to a font file, or a list containing name and file elements with name indicating the font alias in the SVG output and file the path to a font file.

...

Arguments passed on to svglite.

Details

See svglite() documentation for information about specifying fonts.

Value

A function with no arguments: call the function to get the current value of the string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
s <- svgstring(); s()

plot.new(); s();
text(0.5, 0.5, "Hi!"); s()
dev.off()

s <- svgstring()
plot(rnorm(5), rnorm(5))
s()
dev.off()

Example output

<?xml version='1.0' encoding='UTF-8' ?>
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 720.00 576.00'>
<defs>
  <style type='text/css'><![CDATA[
    line, polyline, path, rect, circle {
      fill: none;
      stroke: #000000;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-miterlimit: 10.00;
    }
  ]]></style>
</defs>
<rect width='100%' height='100%' style='stroke: none; fill: #FFFFFF;'/>
</svg>
<?xml version='1.0' encoding='UTF-8' ?>
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 720.00 576.00'>
<defs>
  <style type='text/css'><![CDATA[
    line, polyline, path, rect, circle {
      fill: none;
      stroke: #000000;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-miterlimit: 10.00;
    }
  ]]></style>
</defs>
<rect width='100%' height='100%' style='stroke: none; fill: #FFFFFF;'/>
<defs>
  <clipPath id='cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA=='>
    <rect x='59.04' y='59.04' width='630.72' height='443.52' />
  </clipPath>
</defs>
<g clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)'><text x='367.07' y='285.15' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='14.67px' lengthAdjust='spacingAndGlyphs'>Hi!</text></g>
</svg>
png 
  2 
<?xml version='1.0' encoding='UTF-8' ?>
<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 720.00 576.00'>
<defs>
  <style type='text/css'><![CDATA[
    line, polyline, path, rect, circle {
      fill: none;
      stroke: #000000;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke-miterlimit: 10.00;
    }
  ]]></style>
</defs>
<rect width='100%' height='100%' style='stroke: none; fill: #FFFFFF;'/>
<defs>
  <clipPath id='cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA=='>
    <rect x='59.04' y='59.04' width='630.72' height='443.52' />
  </clipPath>
</defs>
<circle cx='545.20' cy='405.72' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
<circle cx='82.40' cy='486.13' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
<circle cx='153.51' cy='75.47' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
<circle cx='150.40' cy='168.02' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
<circle cx='666.40' cy='278.18' r='2.70pt' style='stroke-width: 0.75;' clip-path='url(#cpNTkuMDR8Njg5Ljc2fDUwMi41Nnw1OS4wNA==)' />
<defs>
  <clipPath id='cpMHw3MjB8NTc2fDA='>
    <rect x='0.00' y='0.00' width='720.00' height='576.00' />
  </clipPath>
</defs>
<line x1='123.27' y1='502.56' x2='610.77' y2='502.56' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='123.27' y1='502.56' x2='123.27' y2='509.76' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='285.77' y1='502.56' x2='285.77' y2='509.76' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='448.27' y1='502.56' x2='448.27' y2='509.76' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='610.77' y1='502.56' x2='610.77' y2='509.76' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text x='112.93' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='20.68px' lengthAdjust='spacingAndGlyphs'>-0.5</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text x='277.43' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>0.0</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text x='439.93' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>0.5</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text x='602.43' y='528.48' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>1.0</text></g>
<line x1='59.04' y1='467.09' x2='59.04' y2='88.19' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='467.09' x2='51.84' y2='467.09' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='403.94' x2='51.84' y2='403.94' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='340.79' x2='51.84' y2='340.79' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='277.64' x2='51.84' y2='277.64' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='214.49' x2='51.84' y2='214.49' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='151.34' x2='51.84' y2='151.34' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<line x1='59.04' y1='88.19' x2='51.84' y2='88.19' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,477.43) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='20.68px' lengthAdjust='spacingAndGlyphs'>-1.5</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,414.28) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='20.68px' lengthAdjust='spacingAndGlyphs'>-1.0</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,351.13) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='20.68px' lengthAdjust='spacingAndGlyphs'>-0.5</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,285.98) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>0.0</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,222.83) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>0.5</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,159.68) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>1.0</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(41.76,96.53) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='16.68px' lengthAdjust='spacingAndGlyphs'>1.5</text></g>
<polyline points='59.04,502.56 689.76,502.56 689.76,59.04 59.04,59.04 59.04,502.56 ' style='stroke-width: 0.75;' clip-path='url(#cpMHw3MjB8NTc2fDA=)' />
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text x='351.40' y='557.28' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='46.00px' lengthAdjust='spacingAndGlyphs'>rnorm(5)</text></g>
<g clip-path='url(#cpMHw3MjB8NTc2fDA=)'><text transform='translate(12.96,303.80) rotate(-90)' style='font-size: 12.00px; font-family: Liberation Sans;' textLength='46.00px' lengthAdjust='spacingAndGlyphs'>rnorm(5)</text></g>
</svg>
png 
  2 

svglite documentation built on Sept. 12, 2017, 1:04 a.m.