sumNodes=FALSE makes sunburst not work
madlogos opened this issue · 2 comments
When I run the following example code, the plot fails to render.
sequences <- read.csv(
system.file("examples/visit-sequences.csv",package="sunburstR")
, header = FALSE
, stringsAsFactors = FALSE
)[1:100, ]
sunburst(sequences, sumNodes=FALSE)
I am using sunburstR
2.0.0 installed from CRAN. Could you look into this?
To be clear, you modified the existing example to use sumNodes=FALSE
?
The sumNodes
argument is a recent addition that was added to deal with a specific data format/structure. The data format/structure used in that example is not appropriate for using the sumNodes=FALSE
option.
An example that uses the sumNodes=FALSE
option is here:
https://github.com/timelyportfolio/sunburstR/blob/master/inst/examples/example_treemap.R
There's a short explanation of why it was added here:
https://github.com/timelyportfolio/sunburstR/blob/1819c49b288a3500f52a6b98f6d0242ce0b77837/vignettes/sunburst-2-0-0.Rmd#sum-nodes
and the issue for adding it (with a much more detailed explanation of its purpose is here:
#62
There could be something said for adding a bit of checking to throw an error before displaying an empty plot, as happens with your modified example.
Thank you, @cjyetman. I modified the test code according to the example you provided. Now it worked correctly.
Vectorize(function(pkg) invisible(require(pkg, character.only=TRUE, quiet=TRUE)))(
c("dplyr", "sunburstR", "treemap", "d3r")
)
sequences <- read.csv(
system.file("examples/visit-sequences.csv", package="sunburstR")
, header = FALSE
, stringsAsFactors = FALSE
)[1:100, ]
seqdat <- dplyr::bind_rows(lapply(
strsplit(as.character(sequences[[1]]), "-"), function(rw)
data.frame(t(rw), stringsAsFactors = FALSE)))
seqdat$size <- sequences$V2
tm <- treemap(seqdat, index=paste("X", 1:6, sep=""), vSize="size", draw=FALSE)
tmnest <- d3_nest(tm$tm[, c(paste("X", 3:6, sep=""), "vSize", "color")],
value_cols = c("vSize", "color"))
sunburst(
data = tmnest,
valueField = "vSize",
count = TRUE,
sumNodes = FALSE
)
I agree that it will be super if there is some data structure validation and error message before rendering the plot. Now I see that sumNodes
is happier to work with treemap lists.