talgalili / dendextend

Extending R's Dendrogram Functionality
153 stars 29 forks source link

Create colored_Dots.R #60

Closed chasemc closed 6 years ago

chasemc commented 6 years ago

I am working on a visualization in one of my Shiny apps and needed circle representation of groups next to the dendrogram instead of bars; this may or may not be helpful to others.

codecov-io commented 6 years ago

Codecov Report

Merging #60 into master will decrease coverage by 0.93%. The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #60      +/-   ##
==========================================
- Coverage    38.6%   37.67%   -0.94%     
==========================================
  Files          49       51       +2     
  Lines        3898     3995      +97     
==========================================
  Hits         1505     1505              
- Misses       2393     2490      +97
Impacted Files Coverage Δ
R/colored_Dots.R 0% <0%> (ø)
R/get_subdendrograms.R 0% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 7d11920...c6e1775. Read the comment docs.

talgalili commented 6 years ago

Thanks for the commit @chasemc Prior to accepting your commit two things are missing: 1) Could you add some roxygen documentation of the function? (you can use the sinew function makeOxygen to help you get the relevant structure). 2) would it be possible to add a unit test or two? (the package uses testthat)

If any of the two are difficult for you since you've never done them before, or if you don't have the time to do it, please just let me know. (I won't have time to do it in the near future, but at least I'll know that I need to do it later).

Thanks again, Tal

chasemc commented 6 years ago

Thanks, those are a little beyond me to be confident to do them correctly. This is 99% the code from your colored_bars(), except some modification the comments here:

if (horiz) {
      # Instead of rectangles, put in points at 1/2 x and y coordinates 
      #rect(-yb, xl, -yt, xr, col = as.character(C[, j]), 
      #     border = as.character(C[, j]))

      points((-yb+(-yt))/2,(xl+xr)/2,pch=19,col = as.character(C[, j]))

      par(srt = 90)
      if (is.null(rowLabels)) {
        s <- as.character(j)
        text(s, pos = 1, offset = 0.5, y = charHeight * 
               text_shift - rotated_str_dim(s)[2]/2, x = -(ystep * 
                                                             (j) * y_scale + y_shift), cex = cex.rowLabels)
      }
      else {
        s <- rowLabels[j]
        text(s, pos = 1, offset = 0.5, y = charHeight * 
               text_shift - rotated_str_dim(s)[2]/2, x = -(ystep * 
                                                             (j) * y_scale + y_shift), cex = cex.rowLabels)
      }
    }
    else {
      # Instead of rectangles, put in points at 1/2 x and y coordinates
      #rect(xl, yb, xr, yt, col = as.character(C[, j]), 
      #    border = as.character(C[, j]))
      points((xl1+xr)/2,(yb+yt)/2,pch=19,col = as.character(C[, j]))
talgalili commented 6 years ago

Hi @chasemc Could you please provide a simple example of how to use your function? Also, could you please explain what each of the argument means? (I can guess some of them, but if you could write this would help)

colors, dend, rowLabels = NULL, cex.rowLabels = 0.9, add = TRUE, y_scale, y_shift, text_shift = 1, sort_by_labels_order = TRUE, horiz = FALSE,

chasemc commented 6 years ago

Thanks for the patience, things are busy right now. But I'll make the example and roxygen as much as I can.

talgalili commented 6 years ago

Hi @chasemc Any news about this?

chasemc commented 6 years ago

Sorry, for having this hang around in your pull requests but I think it will be a nice addition as we're using it heavily within a Shiny app now (see pic). I've got the roxygen done and will be able to write the example(s) for it after my PhD preliminary exam next Wednesday (writing it will be a nice reprieve). Best, -Chase

a

chasemc commented 6 years ago

I was able to add Roxygen, as well as examples similar to "colored_bars". Unfortunately, I don't feel comfortable enough with testthat yet.

talgalili commented 6 years ago

Thanks. I'll try to look into it within the next week or so.