Coder Social home page Coder Social logo

ggrough's Introduction

ggRough

What is ggrough?

ggrough is an R package that converts your ggplot2 plots to rough/sketchy charts, using the excellent javascript roughjs library.

library(ggplot2)
count(mtcars, carb) %>%
  ggplot(aes(carb, n)) +
  geom_col() + 
  labs(title="Number of cars by carburator count") + 
  theme_grey(base_size = 16) -> p 
p

library(ggrough)
options <- list(
  Background=list(roughness=8),
  GeomCol=list(fill_style="zigzag", angle_noise=0.5, fill_weight=2))
get_rough_chart(p, options)

How to install

install.packages("devtools") # if you have not installed "devtools" package
devtools::install_github("xvrdm/ggrough")

How to use

Call get_rough_chart(), using your ggplot2 chart as the first argument. See this page for more ggrough examples and all the available options to customize your output.

Word of caution

ggrough is a work in progress and still has big bugs. Contributions are welcome!

ggrough works “ok” with RStudio Viewer. However you need to redraw your chart everytime you change the size of the Viewer tab and the charts will redraw when you try to copy it via Export -> Save As Image. The latter can be annoying since some roughjs settings can add a lot of randomness.

ggrough doesn’t work well with Rmarkdown files yet. For example, it can only generate one chart per document. If you have multiple charts it overlays them on top of each other.

Under the hood

ggrough is an htmlwidget. It converts your ggplot2 chart to SVG using the package svglite then parse the different elements (<rect>, <path>, <circle>…) to create a chart in a HTML Canvas element[1] with roughjs.

An article explaining how ggrough works is in the making, to help potential contributors get started.

Thanks

This package is only possible thanks to the massive work of:

  1. roughjs can also render to SVG. This will be supported by ggrough in the future

ggrough's People

Contributors

xvrdm avatar

Watchers

 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.