Git Product home page Git Product logo

Comments (9)

outlace avatar outlace commented on May 28, 2024 1

Thanks so much! And oh I'm not computing confidence intervals for the observed data, although I maybe I could using a bootstrapping procedure, maybe I should try that... I'm merely trying to add standard deviation bars to the expected bars which are generated from a null model.

from complex-upset.

krassowski avatar krassowski commented on May 28, 2024 1

@VirtualSpaceman you did all well, it is just that there were many changes since version 0.4.0 and that code does not work any more. I will look into that.

from complex-upset.

krassowski avatar krassowski commented on May 28, 2024

Thank you! Sure, I would approach it like this:

upset(
    observed, sets,
    base_annotations=list(
        'Intersection size'=upset_annotate(
            '..count..',
            list(
                geom_bar(
                    aes(fill='observed'),
                    width=0.35,
                    position=position_nudge(x=-0.2)
                ),
                geom_bar(
                    data=expected,
                    aes(fill='expected'),
                    width=0.35,
                    position=position_nudge(x=+0.2)
                )
            )
        )
    )
)

As an exmple:

image

observed = data.frame(
    a=c(TRUE, FALSE, FALSE, TRUE, TRUE),
    b=c(TRUE, TRUE, TRUE, FALSE, TRUE),
    c=c(FALSE, TRUE, TRUE, FALSE, FALSE),
    d=c(FALSE, FALSE, TRUE, FALSE, FALSE)
)
sets = c('a', 'b', 'c', 'd')

then if you have expected counts as a list, create a data frame (each intersection is represented as hyphenated character/string):

expected_summary = data.frame(
    exepcted_count=c(
        'a-b'=3,
        'b-c-d'=1,
        'b-c'=1,
        'a'=0
    )
)
expected_summary$intersection = rownames(expected_summary)
expected_summary

Screenshot from 2020-05-05 16-59-10

and transform to counts format:

expected = expected_summary[
     rep(seq_len(nrow(expected_summary)), expected_summary$exepcted_count),
    1:2
]
expected

Screenshot from 2020-05-05 16-59-14

You can get the intersections data using upset_data() on your data.

Would that work for you?

from complex-upset.

outlace avatar outlace commented on May 28, 2024

Yes I think that will work. Thanks so much for the quick reply.

from complex-upset.

outlace avatar outlace commented on May 28, 2024

I got it working with my data, thanks again! One last thing. I'm having a hard time adding a geom_errorbar to the expected bars. When I add it gets added to the set intersection dot part on the bottom.

from complex-upset.

krassowski avatar krassowski commented on May 28, 2024

This is due to the order the plots are assembled - the "dots matrix" is the last one added. With multi-pane plot I had to create a bit different interface (inspired by ComplexHeatmap among others) which requires to specify where the geom should be added. For geom bars one could do:

intersections_data = upset_data(observed, sets)
intersection_sizes = unique(
    intersections_data$with_sizes[, c('intersection', 'intersection_size')]
)
intersection_sizes

Screenshot from 2020-05-06 04-35-18

confidence_intervals = binom::binom.confint(
    intersection_sizes$intersection_size,
    nrow(observed),
    method='wilson'
)
confidence_intervals$intersection = intersection_sizes$intersection
confidence_intervals

Screenshot from 2020-05-06 04-35-24

upset(
    observed, sets,
    base_annotations=list(
        'Intersection size'=upset_annotate(
            '..count..',
            list(
                geom_bar(
                    aes(fill='observed'),
                    width=0.35,
                    position=position_nudge(x=-0.2)
                ),
                geom_bar(
                    data=expected,
                    aes(fill='expected'),
                    width=0.35,
                    position=position_nudge(x=+0.2)
                ),
                geom_errorbar(
                    data=confidence_intervals,
                    aes(
                        ymin=lower * nrow(observed),
                        ymax=upper * nrow(observed),
                        y=NULL     # overwrite the default y=..count...
                    ),
                    width=0.2,
                    position=position_nudge(x=-0.2)
                )
            )
        )
    )
)

image

It might be also interesting to apply this to intersection ratios.

Can you share how you calculate the confidence intervals? I would be curious to learn!

I just saw that you mention the expected bars (which might make more sense) - but the relevant code is easy to adjust I guess.

from complex-upset.

outlace avatar outlace commented on May 28, 2024

Hmm would there be a way to directly enter the intersect size counts for my expected bar? When trying to add the SEMs as a geom_errorbar the ymin/max arrays need to be as long as the input observation data which doesn't make sense to me. I have 62 bars for 62 different set intersections but it wont let me put in an array of length 62.

from complex-upset.

krassowski avatar krassowski commented on May 28, 2024

from complex-upset.

VirtualSpaceman avatar VirtualSpaceman commented on May 28, 2024

Hi,

I tried to reproduce the exact plot according to Mike's instructions and code, but I couldn't. I'm getting the output in below.

Screen Shot 2021-08-27 at 15 07 00

As this issue is from last year, maybe some internals have changed and this way doesn't work anymore. As I'm a newcomer in R programming language, I would like to ask: which modifications should I do to reproduce the double bar plot?

Thanks.

from complex-upset.

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.