Code Monkey home page Code Monkey logo

Comments (3)

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

Thanks, I am happy to hear that you like the package.

Right now it is not possible to display the magnitude of an effect without custom labels.
And because I have never encountered any examples, where that was done, I would be wary adding it, to not overload the interface with too many options. Or is this a very common visualization in economics?

from ggsignif.

chinwobble avatar chinwobble commented on May 29, 2024

I wouldn't say this is a common visualisation in economics.
For my specific visualisation I would like to label the magnitude difference somehow to draw specific attention a trend.

from ggsignif.

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

One option is that you write your own method, which returns a string just the way you want it:

magnitude_test <- function(x,y, ...){
  change <- mean(y)/mean(x)
  p <- t.test(x,y)$p.value
  stars <- if(p < 0.001)
    "***"
  else if(p < 0.01)
    "**"
  else if(p < 0.05)
    "*"
  else
    ""
  list(p.value=paste0(signif(change, digits=2),stars))
}

ggplot(mpg, aes(x=manufacturer, y=displ)) +
  geom_boxplot()  +
  stat_signif(comparisons=list(c("audi", "ford"), c("hyundai", "nissan")),
              test=magnitude_test,
              margin_top=0.02, step_increase=0, tip_length=0.01) +
  theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
  facet_wrap(~ as.factor(year), scale="free")

image

You can do whatever kind of calculations you want in the function, the only requirement is that the test returns a list with an entry called p.value.

If you want to try this yourself, you will have to install the latest version of ggsignif from github

devtools::install_github("const-ae/ggsignif")

because only that one supports test methods that return text.

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.