Title: | Universal Graphics Device |
---|---|
Description: | A unified R graphics backend. Render R graphics fast and easy to many common file formats. Provides a thread safe 'C' interface for asynchronous rendering of R graphics. |
Authors: | Florian Rupprecht [aut, cre] , Kun Ren [ctb], Tatsuya Shima [ctb], Jeroen Ooms [ctb] , Hadley Wickham [cph] (Author of included svglite code), Lionel Henry [cph] (Author of included svglite code), Thomas Lin Pedersen [cph] (Author and creator of included svglite code), T Jake Luciani [cph] (Author of included svglite code), Matthieu Decorde [cph] (Author of included svglite code), Vaudor Lise [cph] (Author of included svglite code), Tony Plate [cph] (Contributor to included svglite code), David Gohel [cph] (Contributor to included svglite code), Yixuan Qiu [cph] (Contributor to included svglite code), Håkon Malmedal [cph] (Contributor to included svglite code), RStudio [cph] (Copyright holder of included svglite code), Brett Robinson [cph] (Author of included belle library), Google [cph] (Copyright holder of included material design icons), Victor Zverovich [cph] (Author of included fmt library), Andrzej Krzemienski [cph] (Author of included std::experimental::optional library) |
Maintainer: | Florian Rupprecht <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.2 |
Built: | 2024-11-03 04:51:36 UTC |
Source: | https://github.com/nx10/unigd |
Universal graphics device
Maintainer: Florian Rupprecht [email protected] (ORCID)
Other contributors:
Kun Ren [email protected] [contributor]
Tatsuya Shima [email protected] [contributor]
Jeroen Ooms [email protected] (ORCID) [contributor]
Hadley Wickham [email protected] (Author of included svglite code) [copyright holder]
Lionel Henry [email protected] (Author of included svglite code) [copyright holder]
Thomas Lin Pedersen [email protected] (Author and creator of included svglite code) [copyright holder]
T Jake Luciani [email protected] (Author of included svglite code) [copyright holder]
Matthieu Decorde [email protected] (Author of included svglite code) [copyright holder]
Vaudor Lise [email protected] (Author of included svglite code) [copyright holder]
Tony Plate (Contributor to included svglite code) [copyright holder]
David Gohel (Contributor to included svglite code) [copyright holder]
Yixuan Qiu (Contributor to included svglite code) [copyright holder]
Håkon Malmedal (Contributor to included svglite code) [copyright holder]
RStudio (Copyright holder of included svglite code) [copyright holder]
Brett Robinson (Author of included belle library) [copyright holder]
Google (Copyright holder of included material design icons) [copyright holder]
Victor Zverovich (Author of included fmt library) [copyright holder]
Andrzej Krzemienski (Author of included std::experimental::optional library) [copyright holder]
Useful links:
Report bugs at https://github.com/nx10/unigd/issues
This function initializes a unigd graphics device.
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) )
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) )
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 |
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
|
reset_par |
If set to |
All font settings and descriptions are adopted from the excellent 'svglite' package.
No return value, called to initialize graphics device.
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") dev.off() # alternatively: ugd_close()
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") dev.off() # alternatively: ugd_close()
This function will only work after starting a device with ugd()
.
ugd_clear(which = dev.cur())
ugd_clear(which = dev.cur())
which |
Which device (ID). |
Whether there were any pages to remove.
ugd() plot(1, 1) hist(rnorm(100)) ugd_clear() # Clear all previous plots hist(rnorm(100)) dev.off()
ugd() plot(1, 1) hist(rnorm(100)) ugd_clear() # Clear all previous plots hist(rnorm(100)) dev.off()
This achieves the same effect as grDevices::dev.off()
,
but will only close the device if it has the unigd type.
ugd_close(which = dev.cur(), all = FALSE)
ugd_close(which = dev.cur(), all = FALSE)
which |
Which device (ID). |
all |
Should all running unigd devices be closed. |
Number and name of the new active device (after the specified device has been shut down).
ugd() hist(rnorm(100)) ugd_close() # Equvalent to dev.off() ugd() ugd() ugd() ugd_close(all = TRUE)
ugd() hist(rnorm(100)) ugd_close() # Equvalent to dev.off() ugd() ugd() ugd() ugd_close(all = TRUE)
Query unigd graphics device static plot IDs.
Available plot IDs starting from index
will be returned.
limit
specifies the number of plots.
This function will only work after starting a device with ugd()
.
ugd_id(index = 0, limit = 1, which = dev.cur(), state = FALSE)
ugd_id(index = 0, limit = 1, which = dev.cur(), state = FALSE)
index |
Plot index. If this is set to |
limit |
Limit the number of returned IDs. If this is set to a
value > 1 the returned type is a list if IDs. Set to |
which |
Which device (ID). |
state |
Include the current device state in the returned result
(see also: |
List containing static plot IDs.
ugd() # Initialize graphics device # Page 1 plot.new() text(.5, .5, "#1") # Page 2 plot.new() text(.5, .5, "#2") # Page 3 plot.new() text(.5, .5, "#3") third <- ugd_id() # Get ID of page 3 (last page) second <- ugd_id(2) # Get ID of page 2 all <- ugd_id(1, limit = Inf) # Get all IDs ugd_remove(1) # Remove page 1 ugd_render(second) # Render page 2 dev.off() # Close device
ugd() # Initialize graphics device # Page 1 plot.new() text(.5, .5, "#1") # Page 2 plot.new() text(.5, .5, "#2") # Page 3 plot.new() text(.5, .5, "#3") third <- ugd_id() # Get ID of page 3 (last page) second <- ugd_id(2) # Get ID of page 2 all <- ugd_id(1, limit = Inf) # Get all IDs ugd_remove(1) # Remove page 1 ugd_render(second) # Render page 2 dev.off() # Close device
Access general information of a unigd graphics device.
This function will only work after starting a device with ugd()
.
ugd_info(which = dev.cur())
ugd_info(which = dev.cur())
which |
Which device (ID). |
List of status variables with the following named items:
$id
: Server unique ID,
$version
: unigd and library versions.
ugd() # Initialize graphics device ugd_info() # Get device information dev.off() # Close device
ugd() # Initialize graphics device ugd_info() # Get device information dev.off() # Close device
This function will only work after starting a device with ugd()
.
ugd_remove(page = 0, which = dev.cur())
ugd_remove(page = 0, which = dev.cur())
page |
Plot page to remove. If this is set to |
which |
Which device (ID). |
Whether the page existed (and thereby was successfully removed).
ugd() plot(1, 1) # page 1 hist(rnorm(100)) # page 2 ugd_remove(page = 1) # remove page 1 dev.off()
ugd() plot(1, 1) # page 1 hist(rnorm(100)) # page 2 ugd_remove(page = 1) # remove page 1 dev.off()
See ugd_save()
for saving rendered plots as files.
This function will only work after starting a device with ugd()
.
ugd_render( page = 0, width = -1, height = -1, zoom = 1, as = "svg", which = dev.cur() )
ugd_render( page = 0, width = -1, height = -1, zoom = 1, as = "svg", which = dev.cur() )
page |
Plot page to render. If this is set to |
width |
Width of the plot. If this is set to |
height |
Height of the plot. If this is set to |
zoom |
Zoom level. (For example: |
as |
Renderer. |
which |
Which device (ID). |
Rendered plot. Text renderers return strings, binary renderers return byte arrays.
ugd() plot(1, 1) ugd_render(width = 600, height = 400, as = "svg") dev.off()
ugd() plot(1, 1) ugd_render(width = 600, height = 400, as = "svg") dev.off()
Convenience function for quick inline plot rendering.
This is similar to ugd_render()
but the plotting code
is specified inline and an unigd graphics device is managed
(created and closed) automatically. Starting a device with ugd()
is
therefore not necessary.
ugd_render_inline( code, page = 0, width = getOption("unigd.width", 720), height = getOption("unigd.height", 576), zoom = 1, as = "svg", ... )
ugd_render_inline( code, page = 0, width = getOption("unigd.width", 720), height = getOption("unigd.height", 576), zoom = 1, as = "svg", ... )
code |
Plotting code. See examples for more information. |
page |
Plot page to render. If this is set to |
width |
Width of the plot. |
height |
Height of the plot. |
zoom |
Zoom level. (For example: |
as |
Renderer. |
... |
Additional parameters passed to |
Rendered plot. Text renderers return strings, binary renderers return byte arrays.
ugd_render_inline({ hist(rnorm(100)) }, as = "svgz") s <- ugd_render_inline({ plot.new() lines(c(0.5, 1, 0.5), c(0.5, 1, 1)) }) cat(s)
ugd_render_inline({ hist(rnorm(100)) }, as = "svgz") s <- ugd_render_inline({ plot.new() lines(c(0.5, 1, 0.5), c(0.5, 1, 1)) }) cat(s)
Get a list of available renderers.
This function will only work after starting a device with ugd()
.
ugd_renderers()
ugd_renderers()
List of renderers with the following named items:
$id
: Renderer ID,
$mime
: File mime type,
$ext
: File extension,
$name
: Human readable name,
$type
: Renderer type (currently either plot
or other
),
$bin
: Is the file a binary blob or text.
ugd_renderers()
ugd_renderers()
See ugd_render()
for accessing plot data directly in memory without
saving as a file.
This function will only work after starting a device with ugd()
.
ugd_save( file, page = 0, width = -1, height = -1, zoom = 1, as = "auto", which = dev.cur() )
ugd_save( file, page = 0, width = -1, height = -1, zoom = 1, as = "auto", which = dev.cur() )
file |
Filepath to save plot. |
page |
Plot page to render. If this is set to |
width |
Width of the plot. If this is set to |
height |
Height of the plot. If this is set to |
zoom |
Zoom level. (For example: |
as |
Renderer. When set to |
which |
Which device (ID). |
No return value. Plot will be saved to file.
ugd() plot(1, 1) tf <- tempfile() on.exit(unlink(tf)) ugd_save(file = tf, width = 600, height = 400, as = "png") dev.off()
ugd() plot(1, 1) tf <- tempfile() on.exit(unlink(tf)) ugd_save(file = tf, width = 600, height = 400, as = "png") dev.off()
Convenience function for quick inline plot rendering.
This is similar to ugd_save()
but the plotting code
is specified inline and an unigd graphics device is managed
(created and closed) automatically. Starting a device with ugd()
is
therefore not necessary.
ugd_save_inline( code, file, page = 0, width = getOption("unigd.width", 720), height = getOption("unigd.height", 576), zoom = 1, as = "auto", ... )
ugd_save_inline( code, file, page = 0, width = getOption("unigd.width", 720), height = getOption("unigd.height", 576), zoom = 1, as = "auto", ... )
code |
Plotting code. See examples for more information. |
file |
Filepath to save plot. |
page |
Plot page to render. If this is set to |
width |
Width of the plot. |
height |
Height of the plot. |
zoom |
Zoom level. (For example: |
as |
Renderer. |
... |
Additional parameters passed to |
No return value. Plot will be saved to file.
tf <- tempfile(fileext=".svg") on.exit(unlink(tf)) ugd_save_inline({ plot.new() lines(c(0.5, 1, 0.5), c(0.5, 1, 1)) }, file = tf)
tf <- tempfile(fileext=".svg") on.exit(unlink(tf)) ugd_save_inline({ plot.new() lines(c(0.5, 1, 0.5), c(0.5, 1, 1)) }, file = tf)
Access status information of a unigd graphics device.
This function will only work after starting a device with ugd()
.
ugd_state(which = dev.cur())
ugd_state(which = dev.cur())
which |
Which device (ID). |
List of status variables with the following named items:
$hsize
: Plot history size (how many plots are accessible),
$upid
: Update ID (changes when the device has received new information),
$active
: Is the device the currently activated device.
ugd() ugd_state() plot(1, 1) ugd_state() dev.off()
ugd() ugd_state() plot(1, 1) ugd_state() dev.off()
Plot a test pattern that can be used to evaluate and compare graphics devices.
ugd_test_pattern()
ugd_test_pattern()
Nothing, but a plot is generated.
## Not run: ugd_test_pattern() ## End(Not run)
## Not run: ugd_test_pattern() ## End(Not run)