Code Monkey home page Code Monkey logo

Comments (6)

vestlink avatar vestlink commented on May 28, 2024

A valid question. I was thinking the same.

Update:

I have three levels and have only used one level (0.2) in this example. Using all would required group-wise / fill-wise comparisons (??).

subs5_freq %>%
group_by(breed, study_area, level ,veg_class) %>%
filter(level == 0.2) %>%
ggplot(aes(x=factor(veg_class), y=freq, fill=factor(level))) +
geom_boxplot(width = 0.75, position = position_dodge(width = .9)) +
facet_grid(study_area~breed) +
geom_signif(comparisons = list(c("1_lessgood", "2_good"),
c("2_good", "3_verygood"),
c("1_lessgood", "3_verygood")),
test = "wilcox.test", map_signif_level=TRUE)

signif plot

In this case however, it would be nice if the somparisons would be stacked

from ggsignif.

vestlink avatar vestlink commented on May 28, 2024

@G-Thomson

Something like this?

ggplot(mpg, aes(class, hwy)) +
geom_boxplot() +
facet_grid(.~type) +
geom_signif(comparisons = list(c("2seater", "compact")), map_signif_level=TRUE)

from ggsignif.

G-Thomson avatar G-Thomson commented on May 28, 2024

@vestlink

This is what I'm aiming for:

example

Update:

Note that while this is possible, its not really what I want.

ggplot(mpg, aes(type, hwy)) +
  geom_boxplot() +
  facet_grid(.~class) +
  geom_signif(comparisons = list(c("auto", "manual")), map_signif_level=TRUE)

rplot
`

from ggsignif.

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

Hi @G-Thomson,

I am afraid it not possible to draw anything across facets, as long as you stay within the ggplot2 framework. But ggplot is build upon gtables, so you can use that package to draw across facet. Here is an answer on stackoverflow demonstrating the basics. But this is something I cannot facilitate with my package.

@vestlink, if I understand you correctly you want to do comparison of groups that are drawn with geom_boxplot(position = "dodge"). Unfortunately this is not automatically because the dodging draws at some to geom_signif unknown location. So it would be necessary to draw the comparisons manually as I did in the advanced example in the README.md. Now you have the further complication that you probably want to draw different brackets per facet. The best code I found to do this looks like this:

ggplot(mpg, aes(type, hwy)) +
    geom_boxplot() +
    geom_signif(data=data.frame(class=c("2seater", "midsize"), type=0, hwy=0, group=1), aes(group=group), annotations="abc", y_position = 46, xmin=1, xmax=2)+
    geom_signif(data=data.frame(class=c("minivan"), type=0, hwy=0, group=1), aes(group=group), annotations="123", y_position = 46, xmin=1, xmax=2)+
    facet_grid(.~class)

image

As this is all pretty complicated I would suggest to just create a new variable that combines the veg_class and level. So the new code would like this:

iris %>%
    mutate(Variable=paste0(Species, "-", Petal.Width > 1)) %>%
    ggplot(aes(x=Variable, y=Sepal.Width, fill=Petal.Width > 1)) +
    geom_boxplot() +
    geom_signif(comparisons = list(c("setosa-FALSE", "versicolor-FALSE"))) +
    facet_wrap(~ I(Sepal.Length > 5.0))

image

from ggsignif.

vestlink avatar vestlink commented on May 28, 2024

@const-ae Thank you for your comments. It is true that things get complicated across facets. I will study the code and suggestions further...

from ggsignif.

G-Thomson avatar G-Thomson commented on May 28, 2024

@const-ae Thanks for getting back to me.

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.