GithubHelp home page GithubHelp logo

NA handling about sunburstr HOT 7 OPEN

timelyportfolio avatar timelyportfolio commented on June 11, 2024
NA handling

from sunburstr.

Comments (7)

timelyportfolio avatar timelyportfolio commented on June 11, 2024 1

ok, @kippjohnson I think I remember this, but maybe I learned something new. It looks like the expected order is deepest first, so this works for me. If you specify -end for each complete path, then I think you can avoid this step, but for me just changing the order seems easier.

library(sunburstR)

#  read the csv data downloaded from the Google Fusion Table linked in the article
data_ex <- read.csv(
  "./inst/examples/example2.csv",
  header = FALSE,
  stringsAsFactors = FALSE
)

# fails
sunburst(data_ex)

library(dplyr)
data_ex$depth <- unlist(lapply(strsplit(data_ex$V1,"-"),length))

data_ex %>%
  arrange(desc(depth), V1) %>%
  sunburst()

from sunburstr.

timelyportfolio avatar timelyportfolio commented on June 11, 2024

@kippjohnson looking now; it fails in JavaScript at row 14. Have not looked at these hierarchies in a while so just need to refamiliarize myself.

from sunburstr.

kippjohnson avatar kippjohnson commented on June 11, 2024

Thanks a lot for looking at this @timelyportfolio

Reordering the dataset as you suggest gets me 90% of the way there, but there is still a small problem (see the two attached example photos):

glipizide-2
glipizide-1

As you can see, there are now two distinct 1st level tracks for each of the drugs (Glipizide here). The first level % should be the sum of each of these two percentages. Terminating each string with "End" as you suggest works but isn't quite the plot that I was attempting to make because it's sort of noisy to look at statically. Is there an easy fix for this? I have considered just labeling the "END" color as white.

Anyway, I appreciate you taking the time to work on this.

from sunburstr.

timelyportfolio avatar timelyportfolio commented on June 11, 2024

I think the answer is no, but can you just add the -end to the 1st level tracks that end at the first level?

data_ex %>%
  mutate(V1 = ifelse(depth==1,paste0(V1,"-end"),V1)) %>%
  arrange(desc(depth), V1) %>%
  sunburst()

Maybe, this is what you have already done.

from sunburstr.

kippjohnson avatar kippjohnson commented on June 11, 2024

Yeah, that works.

from sunburstr.

timelyportfolio avatar timelyportfolio commented on June 11, 2024

@kippjohnson I think I understand better now. Here is a hacky way to accomplish an invisible end without having to specify an entire color map.

data_ex %>%
  mutate(V1 = ifelse(depth==1,paste0(V1,"-end"),V1)) %>%
  arrange(desc(depth), V1) %>%
  sunburst() %>%
  htmlwidgets::onRender(
    htmlwidgets::JS(
"
function(el,x){
  var endpaths = d3.select(el)
    .selectAll('path')[0]
    .filter(function(d){
      return d3.select(d).datum().name === 'end'
    });
  d3.selectAll(endpaths).style('fill','none');
}
"      
    )    
  )

I should probably make this a function.

from sunburstr.

kippjohnson avatar kippjohnson commented on June 11, 2024

This is perfect! Thanks a lot

from sunburstr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.