Open tungttnguyen opened 3 years ago
Hi tungttnguyen,
I am not sure if you are still looking for a solution to this problem, but I believe I may have found a solution. I was running into the same error you are talking about with my own data.
I am currently working on your sunburst chart example, although I believe this should be applicable to your treemap as well.
I believe your node structure is implying that you want "Basin" to be your root node, where the values for "MAC" and "King" sum up to be the total value of your sunburst chart. If that is the case, then you should include another row in DF where the cell for parents is an empty string (""), label is ("Basin"), and value is (0). I've modified your code to reflect this.
I apologize first for the apparent "messiness" of the following code. I'm not sure how to insert the code as neatly as you did in your comment, so I've just copied my code and pasted it inside of my comment. This is my first time posting in a comment section inside of a github repository.
:)
----- Code -----
DF <- data.frame(
parents = c("Mid Stream","Mid Stream","Mid Stream","Mid Stream", "Mid Stream","Mid Stream","Mid Stream","Mid Stream", "Mid Stream","Mid Stream","Mid Stream","Mid Stream", "Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Mac River","Mac River","Mac River", "Mac River","Mac River","Mac River","Mac River", "Mac River","Mac River","Mac River","Mac River", "Mac River","Mid Stream","Mid Stream", "Mid Stream","Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Low Stream","Low Stream", "Low Stream","Low Stream", "Low Stream","Upp King","Upp King","Upp King", "Upp King","Upp King","Upp King","Upp King", "Upp King","Upp King","Upp King","Upp King", "Upp King","Upp King","Upp King","Upp King", "Upp King","Upp King","Upp King","Upp King", "Mid King","Mid King","Mid King","Mid King","Mid King", "Mid King","Mid King","Mid King", "Low King","Low King","Low King", "Low King","Low King","Low King", "Low King","Low King", "Low King","Low King","Low King", "Low King","Mid King","Low King", "Low King","Low King", "Low King","Low King","Low King", "Low King","MAC","MAC","MAC","King","King", "King","Basin","Basin", ""),
labels = c("MAC01","MAC02", "MAC03","MAC04","MAC05","MAC06","MAC07", "MAC08","MAC09","MAC10","MAC11","MAC12","MAC13", "MAC14","MAC15","MAC16","MAC17","MAC18", "MAC20","MAC21","MAC22","MAC23","MAC24","MAC25", "MAC26","MAC27","MAC28","MAC29","MAC30", "MAC32","MAC33","MAC34","MAC35","MAC36","MAC37", "MAC38","MAC39","MAC40","MAC41","MAC42","MAC43", "MAC44","MAC45","MAC46","MAC47","MAC48", "MAC49","MAC50","MAC51","MAC52","MAC53","MAC54", "MAC55","MAC56","MAC57","MAC58","MAC59", "MAC60","MAC61","MAC62","MAC63","King01","King02", "King03","King04","King05","King06","King07", "King08","King09","King10","King11","King12", "King13","King14","King15","King16","King17", "King18","King19","King20","King21","King22", "King23","King24","King25","King26","King27", "King28","King29","King30","King31", "King31c","King36","King37","King38","King39", "King40","King41","King42","King43","King50", "King51","King52","King53","King54","King55", "King56","Mid Stream","Low Stream","Mac River", "Upp King","Mid King","Low King","MAC","King", "Basin"),
value = c(16611,1960,8, 183,15,0,242,1346,1780,19,1225,107,145,76, 10,233,216,14,2,238,103,75,2311,28106, 9308,3118,2959,NA,447,1127,64,939,141, 37083,NA,27775,3454,551,335,678,2,783,14, 367,398,160,184,1492,42,38,1101,4694,465, 142,570,2462,72,6,16,237,12356,0,80,2,0, 533,2465,3,40,816,187,28,9,87,283,613, 1,114,160,40,39,78,88,45,83,579,43,120, 227,69,123,118,7,384,5,249,614,37,27, 102,0,18339,1027,582,245,25634,27139,162, 25626,96298,46681,5461,1075,75090,168605, 81626, 0) )
----- End of Code -----
You'll notice that at the end at the end of the parents vector there is an additional empty string value (""); at the end of the labels vector there is an additional value ("Basin"); and there is finally an additional (0) value at the end of your value vector.
When you do this, you should see a 117th row in DF, like in the image below.
Then, when you run your echart4r code, your chart should appear the way I think you meant it to.
----- Code -----
DF_tree <- data.tree::FromDataFrameNetwork(DF)
DF_tree %>% e_charts() %>% e_sunburst() %>% e_tooltip()
----- End of Code -----
I hope this has helped in some way.
Best, Andrew
No problem, and thanks for the info about the packages!
Hi John,
Thanks for working on this awesome package! I am loving it so far! One issue I have at the moment is that the
e_sunburst
ande_treemap
did not use the wholedata.tree
structure when generate sunburst or treemap charts. An example is posted below. Please let me know if I did something wrong!Create data tree structure
Sunburst plot missing data from the
King
branchTreemap plot missing data from the
King
branchIf I created the Treemap for just the data from the
King
branch, they showed upThese are the plots generated by the
treemap
andhighcharter
packages for comparisonCreated on 2021-05-23 by the reprex package (v2.0.0)