Open captcoma opened 6 years ago
Running into the same issue. Pretty sure it's related to #63, wasn't able to make that solution work for me though.
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)
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 ]
The original error is also explained here: https://stackoverflow.com/a/40391432/880783
Dear Constantin
Thank you very much for your package ggsignif, I very appreciate it. I try to add results from chi-square test to a ggplot and it was mentioned, that I could use ggsignif:
https://stackoverflow.com/questions/51886623/compare-dependent-proportions-in-a-ggplot
Moreover I found your adivce to use geom_signif
https://github.com/const-ae/ggsignif/issues/23
However, If i add this to my plot:
I get this error: _Warning: Ignoring unknown aesthetics: annotations, xmin, xmax, yposition Error in FUN(X[[i]], ...) : object 'response' not found
If i leave out geom_signif(...) everything works. Thank you for any advice, Jacob