Code Monkey home page Code Monkey logo

Comments (4)

jchellmuth avatar jchellmuth commented on May 28, 2024

I can confirm that having control over the tip_length when using stat = 'identity' would be very useful
Thanks for looking into it!

from ggsignif.

const-ae avatar const-ae commented on May 28, 2024

Hi thanks for raising the issue. You are right that this is confusing that tip_length has no effect if stat = "identity", but this is actually the intended behavior.

If stat="signif" I am internally computing the correct starting and end points for the lines which are subsequently passed to the geom_signif(stat="identity", ...).

So to add tips if stat = "identity" you will need to do something like this:

dat <- data.frame(Group = c("S1", "S1", "S2", "S2"),
                  Sub   = c("A", "B", "A", "B"),
                  Value = c(3,5,7,8))

ggplot(dat, aes(Group, Value)) +
      geom_bar(aes(fill = Sub), stat="identity", position="dodge", width=.5) +
      geom_signif(stat="identity",
                  data=data.frame(x=c(0.875, 0.875, 1.125), xend=c(0.875, 1.125, 1.125),
                                  y=c(5.3, 5.8, 5.8), yend=c(5.8, 5.8, 5.3),
                                  annotation=c("***")),
                  aes(x=x,xend=xend, y=y, yend=yend, annotation=annotation))
  

image

I understand that this might seem tedious, so I am considering adding another stat (maybe stat="signifmanual"), which simplifies this but this would be a little bit more work.

from ggsignif.

tobadia avatar tobadia commented on May 28, 2024

Indeed this makes sense. I hadn't realized the length of y and yend wasn't necessarily the same as the data in your code here https://github.com/Artjom-Metro/ggsignif/blob/master/R/significance_annotation.R#L71

If it's just a matter of passing a tip extremity as 1st value e.g. y = c(y_lower_tip, y_bar, y_bar) then it's not as bad as I thought: I feared the whole layer had to be altered, and since I'm not familiar with how they are coded, i was expectign something complicated.

This might warrant a mention in the vignette though, maybe replace the identity example with the one you just posted here including a comment on the length of y/yend vectors.

Thanks for the input though!

from ggsignif.

const-ae avatar const-ae commented on May 28, 2024

Hi, I have just released a new version 0.3.0 that simplifies the definition of custom locations, by adding a xmin and xmax parameter to the function.

dat <- data.frame(Group = c("S1", "S1", "S2", "S2"),
                  Sub   = c("A", "B", "A", "B"),
                  Value = c(3,5,7,8))

ggplot(dat, aes(Group, Value)) +
  geom_bar(aes(fill = Sub), stat="identity", position="dodge", width=.5) +
  geom_signif(annotation="***", 
              y_position=5.8, xmin=0.875, xmax=1.125, tip_length = 0.01)

image

As you see, it is no longer necessary to use stat="identity" and also the tip_length parameter works.

from ggsignif.

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.