Skip to contents

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.

Usage

ugd_render_inline(
  code,
  page = 0,
  width = getOption("unigd.width", 720),
  height = getOption("unigd.height", 576),
  zoom = 1,
  as = "svg",
  ...
)

Arguments

code

Plotting code. See examples for more information.

page

Plot page to render. If this is set to 0, the last page will be selected. Can be set to a numeric plot index or plot ID (see ugd_id()).

width

Width of the plot.

height

Height of the plot.

zoom

Zoom level. (For example: 2 corresponds to 200%, 0.5 would be 50%.)

as

Renderer.

...

Additional parameters passed to ugd(...)

Value

Rendered plot. Text renderers return strings, binary renderers return byte arrays.

Examples

ugd_render_inline({
  hist(rnorm(100))
}, as = "svgz")
#>    [1] 1f 8b 08 00 00 00 00 00 00 03 cd 57 5b 6f db 36 14 7e cf af e0 14 0c 4d
#>   [25] 80 98 22 29 ea e6 58 06 b2 15 5d 1f fa 30 60 7b 2b fa a0 4a b2 ac 56 96
#>   [49] 3c 49 89 ed 0d fb ef 3d 24 25 d9 8e 2d c5 d6 96 c0 0e e0 90 1f e9 ef 5c
#>   [73] 79 78 38 29 9f 62 b4 5e a4 59 e9 69 f3 aa 5a 8e 75 7d b5 5a e1 95 81 f3
#>   [97] 22 d6 19 21 44 87 1d 9a da 32 5e a7 49 f6 fd d8 46 ea ba ae 2e 57 35 14
#>  [121] a4 7e 59 b3 c5 a1 86 56 49 58 cd 3d cd 66 04 13 a2 a1 79 94 c4 f3 ca d3
#>  [145] 4c db 92 f3 a7 24 5a fd 92 af 3d 8d 20 82 d4 26 54 af 4d af 26 61 34 2b
#>  [169] a7 57 08 4d ca 6a 93 46 a8 da 2c 23 ef 5d 15 ad 2b 3d 28 cb 77 d3 c9 4f
#>  [193] 9f 7f 7d ff f0 e7 c3 67 d8 82 10 56 22 11 a8 11 dd b5 b3 65 9e 6e 0e 91
#>  [217] 38 cf 76 00 bf 9a 6f 67 45 14 54 db 59 90 14 01 48 fe 47 4a 40 68 96 a4
#>  [241] e9 18 65 79 16 dd d7 48 59 15 f9 f7 68 8c ae 89 fc ec c3 23 21 39 f0 97
#>  [265] 63 54 e4 8f 59 78 64 f1 5b 9e 64 c7 57 17 49 15 15 69 02 ff c6 88 0a bf
#>  [289] a8 f5 7f e1 fb cb 97 e9 44 97 2e 01 1f 05 69 b2 fc 1d 2c 40 49 e8 69 01
#>  [313] b8 6d 22 2c 40 c2 a5 d2 c3 9b 66 d0 1f 09 1d 28 1b aa 03 56 ba c3 6a ba
#>  [337] 98 70 49 5b 8f 6a 5e cb 20 d8 66 5b 5e ce 0d 6c b2 e7 bc ba 0a a9 62 ab
#>  [361] 7f 49 09 f9 79 fb 3b 35 93 d6 79 5a e3 5d e9 71 e5 fc eb 0f f2 73 0f cc
#>  [385] 57 93 18 09 ee 91 88 a0 a7 3d 16 e9 cd 75 40 6e 45 e6 c4 d3 89 c8 13 a1
#>  [409] b0 61 73 cc 95 23 0c 8e 6d 5b 43 62 65 e4 67 c1 3c 2f 3c 6d 91 84 61 1a
#>  [433] b5 12 67 79 56 8d 66 fe 22 49 37 63 f4 29 f9 1a 15 7e 95 e4 19 fa c3 cf
#>  [457] ca 7b b9 58 26 7f 83 46 54 90 2e d7 0a 5a 49 dd c7 e8 6b 9e 86 f7 8a ff
#>  [481] 53 94 c5 42 29 46 0c 4c 8d e5 5a 43 a9 44 1e c2 6f 8f 25 98 59 2e fd 20
#>  [505] c9 e2 87 2c fc 2d dd 2c e7 a5 36 fd 98 94 55 1e 17 fe 02 e5 33 54 64 79
#>  [529] b1 b8 01 5f dc 4e 74 41 07 5e 8c 3b cd 32 4d 1b 33 e7 7f b2 8b 41 36 80
#>  [553] 5d fb 56 58 0e 36 ec 53 8c 78 41 ef aa 00 71 33 d8 e2 69 72 98 fa 55 74
#>  [577] 03 22 5d eb 8e 39 04 3b e4 16 ce 42 25 c0 91 2b d2 f4 f6 55 8d 02 94 9d
#>  [601] 62 d4 87 22 fa eb 31 ca 82 cd 9e 4d e2 f8 a2 35 f5 34 87 a9 40 c0 d0 24
#>  [625] 0c 9b 16 d4 4b 06 f4 96 a5 70 b6 c5 f7 d2 7a 24 f3 7f 8c e0 dc 98 2a 9d
#>  [649] 5f a2 6c 60 c9 e8 62 fb 0c 46 28 d1 98 1d a1 6c f1 01 9c 06 55 45 fc 39
#>  [673] 67 8b 0f e0 e4 06 83 34 38 e4 6c f1 01 9c 26 77 b1 75 84 b3 c5 07 70 b6
#>  [697] d1 ed 8d fa 49 9c 3b 87 ba 09 30 fc 96 39 98 bf ea 99 a6 14 bb 27 9d e9
#>  [721] 91 d1 55 83 da e4 b9 2c 7d 59 67 cd 6c 12 f3 b2 f4 a5 5d fa b6 49 ff 16
#>  [745] fa da d8 e2 a7 a8 4b ba b4 6d 8f d3 25 69 db e9 db f6 a0 5e 92 b6 ec f8
#>  [769] 0d d3 f4 5c a2 3e 3a 16 f4 13 75 fd aa 61 18 ba 26 dc 65 67 54 c4 0e 42
#>  [793] 8a 9d 9a b0 81 07 30 1a 0e 74 0b d6 01 63 03 0f 60 64 d0 0c 98 ce 01 63
#>  [817] 03 0f 60 a4 ae 3a 59 cf 18 1b 78 00 63 1d 81 67 84 a7 c5 a5 b7 3d e2 14
#>  [841] 2e 91 3b 15 8f b7 6c 8f fe 5b 3d e8 31 45 25 c2 25 9a 62 9e 6b 8a ca c0
#>  [865] b7 34 85 9a d0 ea 9f 54 f8 ce 8e 8b 4a fe cb 34 e6 ec c8 c8 83 77 91 b6
#>  [889] b0 fd c0 c0 d7 b1 67 2c 95 cf d8 e6 d1 bd ed 0b 39 5c 5b a2 e6 d5 6f 67
#>  [913] d3 91 0b ed e3 d9 7d e1 99 51 bf a1 df 1b e2 4f 15 9f 46 06 e5 a4 69 36
#>  [937] 38 b3 31 b7 bb 84 c0 d4 b2 87 0a d9 76 8c cd 7d 70 5c 88 6b 63 bb b7 b4
#>  [961] f7 08 61 f0 1e ae 1b 91 e6 8a e8 72 97 39 dc 5f 3b cd 24 35 b8 bc 2c 8f
#>  [985] 4b 31 4c 26 37 0e 93 b2 7d e6 db 66 4f 50 38 25 c3 a3 b2 d3 67 32 03 da
#> [1009] 56 da 25 85 99 1c b3 de fb ac 4f 8a 4b 9b d8 bf a2 c3 76 ba 50 03 86 8c
#> [1033] 77 06 df b0 b0 e3 0e 94 62 11 a7 09 3e 27 76 8f c7 6c e7 7c 87 a9 ba 50
#> [1057] 3e c5 d3 1f cb 2b 2b c5 a0 15 00 00

s <- ugd_render_inline({
  plot.new()
  lines(c(0.5, 1, 0.5), c(0.5, 1, 1))
})
cat(s)
#> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" class="httpgd" width="720.00" height="576.00" viewBox="0 0 720.00 576.00">
#> <defs>
#>   <style type='text/css'><![CDATA[
#>     .httpgd line, .httpgd polyline, .httpgd polygon, .httpgd path, .httpgd rect, .httpgd circle {
#>       fill: none;
#>       stroke: #000000;
#>       stroke-linecap: round;
#>       stroke-linejoin: round;
#>       stroke-miterlimit: 10.00;
#>     }
#>   ]]></style>
#> <clipPath id="c0"><rect x="0.00" y="0.00" width="720.00" height="576.00"/></clipPath>
#> <clipPath id="c1"><rect x="59.04" y="59.04" width="630.72" height="443.52"/></clipPath>
#> </defs>
#> <rect width="100%" height="100%" style="stroke: none;fill: #FFFFFF;"/>
#> <g clip-path="url(#c0)">
#> </g><g clip-path="url(#c1)">
#> <polyline points="374.40,280.80 666.40,75.47 374.40,75.47" style="stroke-width: 0.75;"/>
#> </g>
#> </svg>