Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/Appsilon/r2d3

R domain specific language for D3.js
https://github.com/Appsilon/r2d3

Last synced: about 2 months ago
JSON representation

R domain specific language for D3.js

Awesome Lists containing this project

README

        

---
title:
output: html_document
params:
website_url: http://appsilondatascience.com
logo_url: https://cdn.rawgit.com/Appsilon/website-cdn/gh-pages/logo-white.png

repo_name: r2d3
repo_url: https://github.com/Appsilon/r2d3
demo_url: http://appsilondatascience.com/demo
chagelog_url: http://appsilondatascience.com/repo_changelog
---

`r params$repo_name`
===========

R domain specific language for D3.js


Data driven documents in R without predefined wrappers. With this package you can create any visualisation possible in D3 directly with R language.

Note: _We are aware of package with a similar _ [_https://github.com/hadley/r2d3_](https://github.com/hadley/r2d3) _, but it is no longer maintained. Only name is the same. Our package is doing a completely different thing than wrapping a D3 for ggplot2. _

Demo {.darkorange}
-------

```{r, eval = F}
library(r2d3)
library(texturer)
library(magrittr)

r2d3({
svg <- d3() %>% select("body") %>% append("svg") %>% attr("width", 500) %>% attr("height", 500)
dashed <- textures() %>% lines() %>% thicker()
dots <- textures() %>% circles() %>% size(5) %>% radius(2)

svg$call(dashed)
svg$call(dots)

svg %>%
selectAll("circle") %>%
data(mtcars) %>%
enter() %>%
append("circle") %>%
attr("cx", ~ .$hp) %>%
attr("cy", ~ .$disp) %>%
attr("r", ~ .$mpg) %>%
attr('pointer-events', 'all') %>%
style("fill", dots) %>%
on("mouseover", ~ d3() %>% select(this) %>% style("fill", dashed)) %>%
on("mouseout", ~ d3() %>% select(this) %>% style("fill", dots))
})
```

```{r, echo=F, screenshot.opts = list(zoom = 0.01)}
suppressMessages(base::source("examples/texturer_demo.R"))
suppressMessages(execute(i))
```





Note: code above will not work with the current version of the package. It is code compatible with our design. Current [working version is here](https://github.com/Appsilon/r2d3/blob/master/examples/texturer_demo.R).

The problem and motivation
-----------

It's natural for a data scientist to look for a better data visualisation methods in R. Although there are many greatly supported R packages that allow to create plots (ggplot2, plotly, rbokeh), when it comes to non-standard visualisations like network graphs, bubble or radial charts you have to look for something created by the community.

If you know JavaScript (JS) you might think about wrapping a D3 component into **htmlwidget** and use it in your RMarkdown report or Shiny app. In fact there are many libraries that were already written to wrap a specific D3 components, for instance: [NetworkGraphs](http://christophergandrud.github.io/networkD3/), [BubbleChart](https://github.com/jcheng5/bubbles), [CoffeeWheel](https://github.com/armish/coffeewheel), etc. .

However only some of them generate truly interactive visualisations, other only allow for image or SVG generation. And when it comes to customisations they are very limited, time-consuming and often difficult to do without an appropraite JS knowledge. Since not many data scientists know JS, for the sake of their work, they often resort to manual editing of produced SVG files or static images in PhotoShop. In other case they order visualisations from D3 specialists. Either way it's diffucult, time and cost consuming to use what's currently available on the market.

So in order to tackle the problems of customised, interactive and pleasent data visualisations we are proposing a standardised package wrapping D3, which will allow data scientises to recreate any data visualisation possible in D3 directly with R language. With a D3-like syntax anyone would be able to create visualisations like those below.

How to install? {.firebrick}
---------------
**Note! This library is still in its infancy. Api might change in the future.**

At the moment it's possible to install this library through [devtools](https://github.com/hadley/devtools).
```
devtools::install_github("Appsilon/`r params$repo_name`")
```

To install [previous version](`r params$changelog_url`) you can run:
```
devtools::install_github("Appsilon/`r params$repo_name`", ref = "0.1.0")
```

How to contribute?
-----------------
If you want to contribute to this project please submit a regular PR, once you're done with new feature or bug fix.

**Changes in documentation**

Both repository **README.md** file and an official documentation page are generated with Rmarkdown, so if there is a need to update them, please modify accordingly a **README.Rmd** file and run a **build_readme.R** script to compile it.

Source code {.darkslide}
-----------

This library source code can be found on [Appsilon Data Science's](`r params$website_url`) Github:


[`r params$repo_url`](`r params$repo_url`)

document.write('<div class="logo"><a href="`r params$website_url`"><img alt="Appsilon Data Science" src="`r params$logo_url`"/></a></div>')

Troubleshooting
-----------------
We used the latest versions of dependencies for this library, so please update your R environment before installation.

Future enhacements {.darkorange}
------------------
- translating basic R expressions to JS
- polishing D3 like syntax R-to-JS runtime
- support for other D3 based plugins
- handling exceptions with nice Documentation Urls(e.g. using R specific functions in R2D3)
- create a documentation
- write unity tests and basic examples coverage tets
- CRAN release

Appsilon Data Science {.footer}
=====================

We Provide End-to-End Data Science Solutions

Get in touch [[email protected]]([email protected])

document.write('<a href="`r params$repo_url`"><img style="position: absolute; margin: 0; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>')