Git Product home page Git Product logo

Comments (5)

krassowski avatar krassowski commented on June 8, 2024

I would need an miminal working example to understand this better. Could you please modify the movies example to showcase what you are trying to achieve, please?

from complex-upset.

cristobalcar avatar cristobalcar commented on June 8, 2024

The idea is to put the median label in the last interception to the right

upset(
  movies, genres, name='genre', width_ratio=0.1, min_size=100,
  base_annotations=list(
    'YEAR'=list(
      aes=aes(x=intersection, y=year),
      geom=list(
        geom_boxplot()
        ,geom_hline(aes(yintercept = median(year))
                    ,color='coral'
                    ,linetype="dashed")
        ,geom_text(aes(max(intersection)
                       ,median(year)
                       ,label = round(median(year),1)
                       , vjust = -1
                       ,color="red"))
      )
    )
  )
)

from complex-upset.

krassowski avatar krassowski commented on June 8, 2024

Two options:

1. Set x = 'Drama-Romance'

This requires adjustment each time you change the order of intersections.

image

Code
upset(
    movies, genres, name='genre', width_ratio=0.1, min_size=100,
    base_annotations=list(
        'Year'=list(
            aes=aes(x=intersection, y=year),
            geom=list(
                geom_boxplot(),
                geom_hline(
                    aes(yintercept = median(year)),
                    color='coral',
                    linetype="dashed"
                ),
                geom_text(
                    aes(
                        y = median(year),
                        label = round(median(year), 1)
                    ),
                    x = 'Drama-Romance',
                    vjust = -1,
                    color = "red",
                    check_overlap = TRUE
                )
            )
        )
    )
)

2. Set x = Inf, hjust=1

This is not great for having this text centred on the last intersection, but possibly closer to what you wanted to achieve.

image

Code
upset(
    movies, genres, name='genre', width_ratio=0.1, min_size=100,
    base_annotations=list(
        'Year'=list(
            aes=aes(x=intersection, y=year),
            geom=list(
                geom_boxplot(),
                geom_hline(
                    aes(yintercept = median(year)),
                    color='coral',
                    linetype="dashed"
                ),
                geom_text(
                    aes(
                        y = median(year),
                        label = round(median(year), 1)
                    ),
                    x = Inf,
                    vjust = -1,
                    hjust = 1,
                    color = "red",
                    check_overlap = TRUE
                )
            )
        )
    )
)

Also, either change the geom_text to annotate or use check_overlap=TRUE (as in examples above) to avoid repetitions of the text written on top of each other.

from complex-upset.

cristobalcar avatar cristobalcar commented on June 8, 2024

Thank you, both worked with the movies data but the dynamic code with my data it returns this error:
Error in if (n > 0) c(NA_integer_, -n) else integer() :
argument is of length zero

from complex-upset.

krassowski avatar krassowski commented on June 8, 2024

It might be a problem in your code. It would be only guessing without seeing it - sorry.

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.