{"id":13831088,"url":"https://github.com/r-lib/svglite","last_synced_at":"2025-05-15T02:05:44.889Z","repository":{"id":5674925,"uuid":"6884753","full_name":"r-lib/svglite","owner":"r-lib","description":"A lightweight svg graphics device for R","archived":false,"fork":false,"pushed_at":"2025-05-07T12:28:58.000Z","size":7287,"stargazers_count":190,"open_issues_count":5,"forks_count":39,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-10T11:52:29.182Z","etag":null,"topics":["r","svg"],"latest_commit_sha":null,"homepage":"https://svglite.r-lib.org","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":null,"code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-11-27T14:29:49.000Z","updated_at":"2025-05-07T22:58:30.000Z","dependencies_parsed_at":"2023-01-14T11:29:38.728Z","dependency_job_id":"29878a0b-760a-4c72-a420-90be2f085f2b","html_url":"https://github.com/r-lib/svglite","commit_stats":{"total_commits":427,"total_committers":20,"mean_commits":21.35,"dds":0.6370023419203747,"last_synced_commit":"39eb053fa2dc8912815385523105b2c604043779"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fsvglite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fsvglite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fsvglite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fsvglite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/svglite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254050677,"owners_count":22006336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r","svg"],"created_at":"2024-08-04T10:01:17.857Z","updated_at":"2025-05-15T02:05:44.882Z","avatar_url":"https://github.com/r-lib.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r}\n#| include: false\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# svglite \u003ca href='https://svglite.r-lib.org'\u003e\u003cimg src=\"man/figures/logo.png\" align=\"right\" height=\"131.5\"/\u003e\u003c/a\u003e\n\n\u003c!-- badges: start --\u003e\n\n[![R-CMD-check](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/svglite/actions/workflows/R-CMD-check.yaml)\n[![CRAN Status Badge](http://www.r-pkg.org/badges/version/svglite)](https://cran.r-project.org/package=svglite)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/svglite/graph/badge.svg)](https://app.codecov.io/gh/r-lib/svglite)\n\u003c!-- badges: end --\u003e\n\nsvglite is a graphics device that produces clean svg output, suitable for use on the web, or hand editing. Compared to the built-in `svg()`, svglite produces smaller files, and leaves text as is, making it easier to edit the result after creation. It also supports multiple nice features such as embedding of web fonts.\n\n## Installation\n\nsvglite is available on CRAN using `install.packages(\"svglite\")`. You can install the development version from github with:\n\n```{r}\n#| eval: false\n# install.packages(\"pak\")\npak::pak(\"r-lib/svglite\")\n```\n\n## Motivation\n\nThe grDevices package bundled with R already comes with an SVG device (using the eponymous `svg()` call). The development of svglite is motivated by the following considerations:\n\n### Speed\n\n`svglite()` is considerably faster than `svg()`. If you are rendering SVGs dynamically to serve over the web this can be quite important:\n\n```{r}\n#| message: false\nlibrary(svglite)\n\nx \u003c- runif(1e3)\ny \u003c- runif(1e3)\ntmp1 \u003c- tempfile()\ntmp2 \u003c- tempfile()\n\nsvglite_test \u003c- function() {\n  svglite(tmp1)\n  plot(x, y)\n  dev.off()\n}\nsvg_test \u003c- function() {\n  svg(tmp2, onefile = TRUE)\n  plot(x, y)\n  dev.off()\n}\n\nbench::mark(svglite_test(), svg_test(), min_iterations = 250, check = FALSE)\n```\n\n### File size\n\nAnother point with high relevance when serving SVGs over the web is the size. `svglite()` produces much smaller files\n\n```{r}\n# svglite\nfs::file_size(tmp1)\n\n# svg\nfs::file_size(tmp2)\n```\n\nIn both cases, compressing to make `.svgz` (gzipped svg) is worthwhile. svglite supports compressed output directly which will be triggered if the provided path has a `\".svgz\"` (or `\".svg.gz\"`) extension.\n\n```{r}\ntmp3 \u003c- tempfile(fileext = \".svgz\")\nsvglite(tmp3)\nplot(x, y)\ninvisible(dev.off())\n\n# svglite - svgz\nfs::file_size(tmp3)\n```\n\n### Editability\n\nOne of the main reasons for the size difference between the size of the output of `svglite()` and `svg()` is the fact that `svglite()` encodes text as styled `\u003ctext\u003e` elements, whereas `svg()` converts the glyphs to polygons and renders these. The latter approach means that the output of `svg()` does not require the font to be present on the system that displays the SVG but makes it more or less impossible to edit the text after the fact. svglite focuses on providing maximal editability of the output, so that you can open up the result in a vector drawing program such as Inkscape or Illustrator and polish the output if you so choose.\n\n### Font support\n\nsvglite uses systemfonts for font discovery which means that all installed fonts on your system is available to use. The systemfonts foundation means that fonts registered with `register_font()` or `register_variant()` will also be available, as will fonts added with `add_fonts()` and `require_font()`. If any of these contains non-standard weights or OpenType features (e.g. ligatures or tabular numerics) this will be correctly encoded in the style block. systemfonts also allows you to embed webfont `@imports` in your file to ensure that the file looks as expected even on systems without the used font installed. Using `systemfonts::fonts_as_import()` you can generate these imports automatically, optionally embedding the font data directly in the file.\n\n## Building svglite\n\n_This section is only relevant for building svglite from scratch, as opposed to installing from a pre-built package on CRAN._\n\nBuilding svglite requires the system dependency libpng. As svglite doesn't have any build-time configuration, your R configuration must point to libpng's `include` and `lib` folders.\n\nFor instance on macOS, install libpng with:\n\n```sh\nbrew install libpng\n```\n\nAnd make sure your `~/.R/Makevars` knows about Homebrew's `include` and `lib` folders where libpng should now be installed. On arm64 hardware, this would be:\n\n```mk\nCPPFLAGS += -I/opt/homebrew/include\nLDFLAGS += -L/opt/homebrew/lib\n```\n\n## Code of Conduct\n\nPlease note that the svglite project is released with a [Contributor Code of Conduct](https://svglite.r-lib.org/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fsvglite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fsvglite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fsvglite/lists"}