I am trying to use the D3 Bubble Chart in R to make my own bubbles chart with grouped bubble colours.
I have upload the index.html and the flare.json files from the D3 into R and it produced the bubble chart when run. But I didn't wanted to manually change this JSON code to create my own bubbles and groups (header below shows a set of 3 bubble groups with names for the different groups).
{
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{"name": "AgglomerativeCluster", "size": 3938},
{"name": "CommunityStructure", "size": 3812},
{"name": "HierarchicalCluster", "size": 6714},
{"name": "MergeEdge", "size": 743}
]
},
{
"name": "graph",
"children": [
{"name": "BetweennessCentrality", "size": 3534},
{"name": "LinkDistance", "size": 5731},
{"name": "MaxFlowMinCut", "size": 7840},
{"name": "ShortestPaths", "size": 5914},
{"name": "SpanningTree", "size": 3416}
]
},
{
"name": "optimization",
"children": [
{"name": "AspectRatioBanker", "size": 7074}
]
}
]
Using the jsonlite package (which from reading online can handle more complex json structures) I have converted to a dataframe.
library(jsonlite)
fromJSON("flare.json",simplifyDateframe = FALSE)
This is without the dataframe structure requested (example).
$children[[10]]$children[[6]]$children[[10]]
$children[[10]]$children[[6]]$children[[10]]$name
[1] "OperatorSwitch"
$children[[10]]$children[[6]]$children[[10]]$size
[1] 2581
This is with the dataframe structure requested (example).
fromJSON("flare.json",simplifyDataFrame = TRUE)
However it produces a long concatenated list of data which I have been trying to untangle to automate with my data.
Arrays, Colors, Dates, Displays, Filter, Geometry, heap, IEvaluable, IPredicate, IValueProxy, math, Maths, Orientation, palette, Property, Shapes, Sort, Stats, Strings, 8258, 10001, 8217, 12555, 2324, 10993, NA, 335, 383, 874, NA, 17705, 1486, NA, 5559, 19118, 6887, 6557, 22026, FibonacciHeap, HeapNode, 9354, 1233, DenseMatrix, IMatrix, SparseMatrix, 3165, 2815, 3366, ColorPalette, Palette, ShapePalette, SizePalette, 6367, 1229, 2059, 2291
Suggested solutions ...
FOR LOOPS (Time-restricted)
I have thought about writing multiple for loops to re-construct the JSON nest structure (which I am stronger at but I have a deadline and this may take a while). But I thought that someone who is more JSON savy might be able to help.
CSV CONVERTED FORMAT (doesn't work)
I also attempted to converted the flare.json file using JSON to CSV convertor to produce the CSV format needed to test whether I could update the content from the CSV directly to R but that didn't work (even with the addition of the flare.json header content that isn't automate from the jsonlite toJSON).
What I really need
A solution for converting the flare.json from JSON into a dataframe or table so I can upload my data with names, sizes and groups to convert back to JSON to produce my own bubble chart?
If possible it would be great to achieve this all in R, which I don't think is impossible but am happy to hear other suggestions.
I am quite stumped as what to do next. I normally deal with matrices in R so dealing with JSON lists and array is not my strong point.