0

I wish to create a simple sankey chart using this piece of data and specifically plotly package such that, activity ABC points to Resouce "R5", "BVN" to "R1" and "IOP" to "R6". I followed the plotly post https://plot.ly/r/sankey-diagram/, but I just am not able to automate the scipt with this data. I would appreciate if you can help me do it without JSON. Data is attached below.

library(plotly)
library(rjson)
json_file <-"https://raw.githubusercontent.com/plotly/plotly.js/master/test/image/mocks/sankey_energy.json"
json_data <- fromJSON(paste(readLines(json_file), collapse=""))

p <- plot_ly(
type = "sankey",
domain = c(
  x =  c(0,1),
  y =  c(0,1)
),
orientation = "h",
valueformat = ".0f",
valuesuffix = "TWh",

node = list(
  label = json_data$data[[1]]$node$label,
  color = json_data$data[[1]]$node$color,
  pad = 15,
  thickness = 15,
  line = list(
    color = "black",
    width = 0.5
  )
),

link = list(
  source = json_data$data[[1]]$link$source,
  target = json_data$data[[1]]$link$target,
  value =  json_data$data[[1]]$link$value,
  label =  json_data$data[[1]]$link$label
)
) %>% 
   layout(
title = "Energy forecast for 2050<br>Source: Department of Energy & Climate Change, Tom Counsell via <a href='https://bost.ocks.org/mike/sankey/'>Mike Bostock</a>",
font = list(
  size = 10
),
xaxis = list(showgrid = F, zeroline = F),
yaxis = list(showgrid = F, zeroline = F)
)

Activity    Resource    Value
ABC         R2          40
BVN         R4          53
NCB         R5          45
UNI         R1          22
IOP         R3          34
GAD         R6          54
Ashmin Kaul
  • 860
  • 2
  • 12
  • 37
  • looks like you gave up with processMap and shifted to sankey now – Hardik Gupta Oct 11 '17 at 09:00
  • Lol, these are bits and pieces which I am stitching for something, if you can help me here, would really appreciate. – Ashmin Kaul Oct 11 '17 at 09:04
  • @Hardikgupta, please help me with this post, need to make it little dynamic. https://stackoverflow.com/questions/47812506/customizing-the-sankey-chart-to-cater-large-datasets – Ashmin Kaul Dec 15 '17 at 06:01

0 Answers0