Code Monkey home page Code Monkey logo

Comments (4)

muhark avatar muhark commented on May 28, 2024

Running into the same issue. Pretty sure it's related to #63, wasn't able to make that solution work for me though.

from ggsignif.

IndrajeetPatil avatar IndrajeetPatil commented on May 28, 2024

Can reproduce:

library(tidyverse)
library(ggsignif)
library(ggalluvial)

df <- data.frame(
  timepoint = rep(0:2, each = 10),
  response = c("A", "B", "A", "A", "A", "A", "A", "A", "B", "B", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "A", "B", "B", "B", "B", "B", "A", "B", "B", "B"),
  variable = rep(c("var1", "var2"), each = 5, 3),
  subject = rep(1:5, 6)
)

df$timepoint <- factor(df$timepoint,
  level = c(1, 0, 2),
  labels = c("method_A", "baseline", "method_B")
)

df %>%
  add_count(timepoint, variable, response) %>%
  add_count(timepoint, variable) %>%
  mutate(freq = n / nn * 100) %>%
  mutate(total = 1) -> df
#> Storing counts in `nn`, as `n` already present in input
#> ℹ Use `name = "new_name"` to pick a new name.

stats <- data.frame(xmax = c(rep(c("baseline", "method_B"), 2)))
stats %>%
  mutate(xmin = as.factor(c(rep(c("method_A", "baseline"), 2)))) %>%
  mutate(annotations = c("1", "0.2", "1", "0.5")) %>%
  mutate(y_position = 5) %>%
  mutate(variable = as.factor(c("var1", "var1", "var2", "var2"))) -> annotation_df

# without
ggplot(
  df,
  aes(
    x = timepoint, stratum = response, alluvium = subject,
    y = total,
    fill = response, label = paste(freq, "%")
  )
) +
  geom_flow() +
  geom_stratum(alpha = .5) +
  geom_text(stat = "stratum", size = 3) +
  theme(legend.position = "none") +
  facet_wrap(~variable)

# with
ggplot(
  df,
  aes(
    x = timepoint, stratum = response, alluvium = subject,
    y = total,
    fill = response, label = paste(freq, "%")
  )
) +
  geom_flow() +
  geom_stratum(alpha = .5) +
  geom_text(stat = "stratum", size = 3) +
  theme(legend.position = "none") +
  geom_signif(
    data = annotation_df,
    aes(annotations = annotations, xmin = xmin, xmax = xmax, y_position = y_position),
    manual = TRUE
  ) +
  facet_wrap(~variable)
#> Warning: Ignoring unknown aesthetics: annotations, xmin, xmax, y_position
#> Error in FUN(X[[i]], ...): object 'response' not found

Created on 2021-01-13 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.3 (2020-10-10)
#>  os       macOS Mojave 10.14.6        
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Berlin               
#>  date     2021-01-13                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version date       lib source        
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 4.0.3)
#>  broom         0.7.3   2020-12-16 [1] CRAN (R 4.0.3)
#>  callr         3.5.1   2020-10-13 [1] CRAN (R 4.0.2)
#>  cellranger    1.1.0   2016-07-27 [1] CRAN (R 4.0.2)
#>  cli           2.2.0   2020-11-20 [1] CRAN (R 4.0.3)
#>  colorspace    2.0-0   2020-11-11 [1] CRAN (R 4.0.2)
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)
#>  curl          4.3     2019-12-02 [1] CRAN (R 4.0.1)
#>  DBI           1.1.0   2019-12-15 [1] CRAN (R 4.0.2)
#>  dbplyr        2.0.0   2020-11-03 [1] CRAN (R 4.0.2)
#>  desc          1.2.0   2018-05-01 [1] CRAN (R 4.0.2)
#>  devtools      2.3.2   2020-09-18 [1] CRAN (R 4.0.2)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.2)
#>  dplyr       * 1.0.2   2020-08-18 [1] CRAN (R 4.0.2)
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.1)
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)
#>  farver        2.0.3   2020-01-16 [1] CRAN (R 4.0.2)
#>  forcats     * 0.5.0   2020-03-01 [1] CRAN (R 4.0.2)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
#>  generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.2)
#>  ggalluvial  * 0.12.3  2020-12-05 [1] CRAN (R 4.0.2)
#>  ggplot2     * 3.3.3   2020-12-30 [1] CRAN (R 4.0.3)
#>  ggsignif    * 0.6.0   2019-08-08 [1] CRAN (R 4.0.2)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.2)
#>  haven         2.3.1   2020-06-01 [1] CRAN (R 4.0.2)
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.2)
#>  htmltools     0.5.1   2021-01-12 [1] CRAN (R 4.0.3)
#>  httr          1.4.2   2020-07-20 [1] CRAN (R 4.0.2)
#>  jsonlite      1.7.2   2020-12-09 [1] CRAN (R 4.0.3)
#>  knitr         1.30    2020-09-22 [1] CRAN (R 4.0.2)
#>  labeling      0.4.2   2020-10-20 [1] CRAN (R 4.0.2)
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)
#>  lubridate     1.7.9.2 2020-11-13 [1] CRAN (R 4.0.3)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
#>  memoise       1.1.0   2017-04-21 [1] CRAN (R 4.0.2)
#>  mime          0.9     2020-02-04 [1] CRAN (R 4.0.2)
#>  modelr        0.1.8   2020-05-19 [1] CRAN (R 4.0.2)
#>  munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.2)
#>  pillar        1.4.7   2020-11-20 [1] CRAN (R 4.0.3)
#>  pkgbuild      1.2.0   2020-12-15 [1] CRAN (R 4.0.3)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
#>  pkgload       1.1.0   2020-05-29 [1] CRAN (R 4.0.2)
#>  prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
#>  processx      3.4.5   2020-11-30 [1] CRAN (R 4.0.3)
#>  ps            1.5.0   2020-12-05 [1] CRAN (R 4.0.3)
#>  purrr       * 0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.2)
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)
#>  readr       * 1.4.0   2020-10-05 [1] CRAN (R 4.0.2)
#>  readxl        1.3.1   2019-03-13 [1] CRAN (R 4.0.2)
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.2)
#>  reprex        0.3.0   2019-05-16 [1] CRAN (R 4.0.2)
#>  rlang         0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
#>  rmarkdown     2.6     2020-12-14 [1] CRAN (R 4.0.3)
#>  rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.0.3)
#>  rvest         0.3.6   2020-07-25 [1] CRAN (R 4.0.2)
#>  scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.2)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)
#>  stringr     * 1.4.0   2019-02-10 [1] CRAN (R 4.0.2)
#>  testthat      3.0.1   2020-12-17 [1] CRAN (R 4.0.3)
#>  tibble      * 3.0.4   2020-10-12 [1] CRAN (R 4.0.2)
#>  tidyr       * 1.1.2   2020-08-27 [1] CRAN (R 4.0.2)
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)
#>  tidyverse   * 1.3.0   2019-11-21 [1] CRAN (R 4.0.2)
#>  usethis       2.0.0   2020-12-10 [1] CRAN (R 4.0.3)
#>  vctrs         0.3.6   2020-12-17 [1] CRAN (R 4.0.3)
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)
#>  xfun          0.20    2021-01-06 [1] CRAN (R 4.0.3)
#>  xml2          1.3.2   2020-04-23 [1] CRAN (R 4.0.2)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)
#> 
#> [1] /Users/patil/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library

from ggsignif.

aubreyghoward avatar aubreyghoward commented on May 28, 2024

I would like to add the the error in (FUN(X[[i]], ...) is caused by a lack of the specification on dataframe supplying the significance values for all required terms in the facted plot. In the above example, there is not a term in the significance dataframe for "response". This can be solved by supplying the discrete arguments for the comparisons you intend to plot. Please see this example code using diamonds below, which I hope clarifies the issue:


library(ggplot2)
library(ggsignif)
rm(list = ls())

diamonds.abbv <- diamonds[diamonds$clarity == c("I1","SI2"),]

df.sig <- data.frame( start = c(0.8, 1.2), 
                        end = c(1.2,1.8),
                        y = c(3,3),
                        cut = c("Fair","Good"),
                        star = c("D", "E"),
                        label = c("#1", "#2"),
                       clarity = c("I1","I1"))
ggplot(data = diamonds.abbv, mapping = aes( x = color,
                                       y = carat,
                                       fill = clarity))+
         geom_boxplot()+
  facet_wrap(~cut)

ggplot(data = diamonds.abbv, mapping = aes( x = color,
                                            y = carat,
                                            fill = clarity))+
  geom_boxplot()+
  facet_wrap(~cut)+
  geom_signif(data = df.sig, manual = TRUE, 
              mapping = aes(xmin = star, xmax = end, y_position = y, annotations = label))
##end run

However, I still get the following error:

[Warning message:
Ignoring unknown aesthetics: xmin, xmax, y_position, annotations ]

from ggsignif.

bersbersbers avatar bersbersbers commented on May 28, 2024

The original error is also explained here:
https://stackoverflow.com/a/40391432/880783

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.