Giter Site home page Giter Site logo

svglite's Introduction

svglite

R build status Codecov test coverage CRAN Status Badge

svglite 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.

Installation

svglite is available on CRAN using install.packages("svglite"). You can install the development version from github with:

# install.packages("devtools")
devtools::install_github("r-lib/svglite")

Benchmarks

While the performance of svglite() and svg() is comparable (with a slight upper hand to svglite)

library(svglite)

x <- runif(1e3)
y <- runif(1e3)
tmp1 <- tempfile()
tmp2 <- tempfile()

svglite_test <- function() {
  svglite(tmp1)
  plot(x, y)
  dev.off()
}
svg_test <- function() {
  svg(tmp2, onefile = TRUE)
  plot(x, y)
  dev.off()
}

plot(bench::mark(svglite_test(), svg_test()), type = 'ridge')

It produces considerably smaller files:

file.size(c(tmp1, tmp2)) / 1024
#> [1]  74.54492 321.01172

In both cases, compressing to make .svgz is worthwhile:

gz <- function(in_path, out_path = tempfile()) {
  out <- gzfile(out_path, "w")
  writeLines(readLines(in_path), out)
  close(out)
  
  invisible(out_path)
}
file.size(gz(tmp1)) / 1024
#> [1] 9.416992
file.size(gz(tmp2)) / 1024
#> [1] 38.55762

svglite's People

Contributors

hadley avatar lionel- avatar yixuan avatar thomasp85 avatar timelyportfolio avatar davidgohel avatar mdecorde avatar vandenman avatar hmalmedal avatar ilia-kats avatar pmur002 avatar tjake avatar jimhester avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.