Coder Social home page Coder Social logo

schmidtpaul / sankeyd3plus Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 726 KB

D3 JavaScript Sankey Diagrams in R

Home Page: https://schmidtpaul.github.io/sankeyD3plus/

License: GNU General Public License v3.0

R 56.30% JavaScript 43.08% CSS 0.62%

sankeyd3plus's Introduction

sankeyD3plus

The R package {sankeyD3plus} lets you create 'D3' 'JavaScript' Sankey diagrams in R.

This package is heavily based on this fork from {sankeyD3}, which in turn is based on {networkD3} and d3-sankey. I decided to create {sankeyD3plus} because

  1. {sankeyD3} has not been maintained for years and the author does not seem to respond to issues
  2. the mentioned fork added a significant improvement
  3. I wanted to add helper functions
  4. I wanted to add more examples in the documentation

Installation

You can install sankeyD3plus like so:

remotes::install_github('SchmidtPaul/sankeyD3plus')

Examples

Check out the Examples page!

sankeyd3plus's People

Contributors

schmidtpaul avatar

Stargazers

Andrew Allen Bruce avatar Kennedi Todd avatar

Watchers

 avatar

sankeyd3plus's Issues

Add examples

The Examples page should have examples for

  • create a diagram asap
  • Labels and Values
  • Link color & Node color
  • Node Positioning
  • x-axis labels
  • value label formatting
  • node padding (the one below)
  • recreating some other public Sankey plots

Suggested Future Enhancements and Improvements

List of enhancements

  • Enhancement 1: Increasing the fontSize should also affect the xAxisDomain
  • Enhancement 2: Enable linebreaks in NodeID and xAxisDomain
  • Enhancement 3: Implement sinksRight = TRUE from networkD3::sankeyNetwork()

Reprex for enhancements

Enhancement 1

links <- data.frame(
  source = c(0, 0, 0, 1, 2),
  target = c(1, 2, 3, 4, 4)
)

sankeyD3plus::sankeyNetwork(
  Links = links,
  Source = "source",
  Target = "target", 
  fontSize = 30,
  nodePadding = 30,
  xAxisDomain = c("One", "Two", "Three")
)

Created on 2023-08-03 with reprex v2.0.2

Enhancement 2

links <- data.frame(
  source = c(0, 0, 1, 2),
  target = c(1, 2, 3, 3),
  value = c(10, 20, 10, 20)
)

nodes <- data.frame(
  label = c("I am using \n in this string",
            "I am using \r in this string",
            "I am using <br> in this string",
            "I am using
            in this string")
)

sankeyD3plus::sankeyNetwork(
  Links = links,
  Nodes = nodes,
  Source = "source",
  Target = "target",
  Value  = "value",
  NodeID = "label",
  xAxisDomain = c("Hello\nWorld", "Hello
                  World", "Hello<br>World")
)

Created on 2023-08-03 with reprex v2.0.2

Enhancement 3

URL <- paste0(
  "https://cdn.rawgit.com/christophergandrud/networkD3/",
  "master/JSONdata/energy.json")
Energy <- jsonlite::fromJSON(URL)
networkD3::sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
                         Target = "target", Value = "value", NodeID = "name",
                         units = "TWh", fontSize = 12, nodeWidth = 30,
                         sinksRight = TRUE)

sankeyD3plus::sankeyNetwork(Links = Energy$links, Nodes = Energy$nodes, Source = "source",
              Target = "target", Value = "value", NodeID = "name",
              units = "TWh", fontSize = 12, nodeWidth = 30,
              NodeGroup = "name")

Created on 2023-08-03 with reprex v2.0.2

Add articles

It would be nice to have

  • an article like Why not use plotly/other packages to create a Sankey diagram?"
  • ?

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.