Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sumNodes=FALSE makes sunburst not work #79

Open
madlogos opened this issue Sep 17, 2018 · 2 comments
Open

sumNodes=FALSE makes sunburst not work #79

madlogos opened this issue Sep 17, 2018 · 2 comments

Comments

@madlogos
Copy link

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?

@cjyetman
Copy link
Collaborator

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.

@madlogos
Copy link
Author

madlogos commented Sep 17, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants