Skip to contents

This function initializes a unigd graphics device.

Usage

ugd(
  width = getOption("unigd.width", 720),
  height = getOption("unigd.height", 576),
  bg = getOption("unigd.bg", "white"),
  pointsize = getOption("unigd.pointsize", 12),
  system_fonts = getOption("unigd.system_fonts", list()),
  user_fonts = getOption("unigd.user_fonts", list()),
  reset_par = getOption("unigd.reset_par", FALSE)
)

Arguments

width

Graphics device width (pixels).

height

Graphics device height (pixels).

bg

Background color.

pointsize

Graphics device point size.

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 systemfonts::font_info().

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.

reset_par

If set to TRUE, global graphics parameters will be saved on device start and reset every time ugd_clear() is called (see graphics::par()).

Value

No return value, called to initialize graphics device.

Details

All font settings and descriptions are adopted from the excellent 'svglite' package.

Examples

ugd() # Initialize graphics device

# Plot something
x <- seq(0, 3 * pi, by = 0.1)
plot(x, sin(x), type = "l")

# Render plot as SVG
ugd_render(width = 600, height = 400, as = "svg")
#> [1] "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" class=\"httpgd\" width=\"600.00\" height=\"400.00\" viewBox=\"0 0 600.00 400.00\">\n<defs>\n  <style type='text/css'><![CDATA[\n    .httpgd line, .httpgd polyline, .httpgd polygon, .httpgd path, .httpgd rect, .httpgd circle {\n      fill: none;\n      stroke: #000000;\n      stroke-linecap: round;\n      stroke-linejoin: round;\n      stroke-miterlimit: 10.00;\n    }\n  ]]></style>\n<clipPath id=\"c0\"><rect x=\"0.00\" y=\"0.00\" width=\"600.00\" height=\"400.00\"/></clipPath>\n<clipPath id=\"c1\"><rect x=\"59.04\" y=\"59.04\" width=\"510.72\" height=\"267.52\"/></clipPath>\n<clipPath id=\"c2\"><rect x=\"0.00\" y=\"0.00\" width=\"600.00\" height=\"400.00\"/></clipPath>\n</defs>\n<rect width=\"100%\" height=\"100%\" style=\"stroke: none;fill: #FFFFFF;\"/>\n<g clip-path=\"url(#c0)\">\n</g><g clip-path=\"url(#c1)\">\n<polyline points=\"77.96,192.78 82.99,180.41 88.02,168.17 93.05,156.17 98.08,144.54 103.11,133.39 108.14,122.83 113.17,112.97 118.20,103.91 123.23,95.74 128.26,88.53 133.29,82.37 138.32,77.31 143.36,73.41 148.39,70.70 153.42,69.21 158.45,68.95 163.48,69.93 168.51,72.14 173.54,75.55 178.57,80.13 183.60,85.84 188.63,92.62 193.66,100.40 198.69,109.10 203.72,118.64 208.75,128.92 213.79,139.83 218.82,151.28 223.85,163.14 228.88,175.30 233.91,187.63 238.94,200.01 243.97,212.32 249.00,224.44 254.03,236.23 259.06,247.60 264.09,258.42 269.12,268.58 274.15,277.98 279.18,286.53 284.22,294.15 289.25,300.75 294.28,306.28 299.31,310.67 304.34,313.88 309.37,315.88 314.40,316.65 319.43,316.19 324.46,314.49 329.49,311.57 334.52,307.47 339.55,302.22 344.58,295.88 349.62,288.51 354.65,280.18 359.68,270.98 364.71,261.00 369.74,250.33 374.77,239.10 379.80,227.39 384.83,215.35 389.86,203.07 394.89,190.70 399.92,178.34 404.95,166.13 409.98,154.18 415.01,142.62 420.05,131.57 425.08,121.12 430.11,111.39 435.14,102.47 440.17,94.46 445.20,87.42 450.23,81.44 455.26,76.58 460.29,72.87 465.32,70.36 470.35,69.08 475.38,69.03 480.41,70.21 485.44,72.63 490.48,76.24 495.51,81.01 500.54,86.91 505.57,93.86 510.60,101.80 515.63,110.65 520.66,120.32 525.69,130.71 530.72,141.72 535.75,153.25 540.78,165.17 545.81,177.36 550.84,189.71\" style=\"stroke-width: 0.75;\"/>\n</g><g clip-path=\"url(#c2)\">\n<line x1=\"77.96\" y1=\"326.56\" x2=\"480.41\" y2=\"326.56\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"77.96\" y1=\"326.56\" x2=\"77.96\" y2=\"333.76\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"178.57\" y1=\"326.56\" x2=\"178.57\" y2=\"333.76\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"279.18\" y1=\"326.56\" x2=\"279.18\" y2=\"333.76\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"379.80\" y1=\"326.56\" x2=\"379.80\" y2=\"333.76\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"480.41\" y1=\"326.56\" x2=\"480.41\" y2=\"333.76\" style=\"stroke-width: 0.75;\"/>\n<g><text x=\"77.96\" y=\"352.48\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.64px\" lengthAdjust=\"spacingAndGlyphs\">0</text></g>\n<g><text x=\"178.57\" y=\"352.48\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.64px\" lengthAdjust=\"spacingAndGlyphs\">2</text></g>\n<g><text x=\"279.18\" y=\"352.48\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.64px\" lengthAdjust=\"spacingAndGlyphs\">4</text></g>\n<g><text x=\"379.80\" y=\"352.48\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.64px\" lengthAdjust=\"spacingAndGlyphs\">6</text></g>\n<g><text x=\"480.41\" y=\"352.48\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.64px\" lengthAdjust=\"spacingAndGlyphs\">8</text></g>\n<line x1=\"59.04\" y1=\"316.66\" x2=\"59.04\" y2=\"68.90\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"59.04\" y1=\"316.66\" x2=\"51.84\" y2=\"316.66\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"59.04\" y1=\"254.72\" x2=\"51.84\" y2=\"254.72\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"59.04\" y1=\"192.78\" x2=\"51.84\" y2=\"192.78\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"59.04\" y1=\"130.84\" x2=\"51.84\" y2=\"130.84\" style=\"stroke-width: 0.75;\"/>\n<line x1=\"59.04\" y1=\"68.90\" x2=\"51.84\" y2=\"68.90\" style=\"stroke-width: 0.75;\"/>\n<g><text transform=\"translate(41.76,316.66) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"23.43px\" lengthAdjust=\"spacingAndGlyphs\">-1.0</text></g>\n<g><text transform=\"translate(41.76,254.72) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"23.43px\" lengthAdjust=\"spacingAndGlyphs\">-0.5</text></g>\n<g><text transform=\"translate(41.76,192.78) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"19.09px\" lengthAdjust=\"spacingAndGlyphs\">0.0</text></g>\n<g><text transform=\"translate(41.76,130.84) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"19.09px\" lengthAdjust=\"spacingAndGlyphs\">0.5</text></g>\n<g><text transform=\"translate(41.76,68.90) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"19.09px\" lengthAdjust=\"spacingAndGlyphs\">1.0</text></g>\n<polygon points=\"59.04,326.56 569.76,326.56 569.76,59.04 59.04,59.04\" style=\"stroke-width: 0.75;\" />\n<g><text x=\"314.40\" y=\"381.28\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"7.11px\" lengthAdjust=\"spacingAndGlyphs\">x</text></g>\n<g><text transform=\"translate(12.96,192.80) rotate(-90.00)\" text-anchor=\"middle\" style=\"font-family: Liberation Sans;font-size: 12.00px;\" textLength=\"33.67px\" lengthAdjust=\"spacingAndGlyphs\">sin(x)</text></g>\n</g>\n</svg>"

dev.off() # alternatively: ugd_close()
#> agg_png 
#>       2