Replies: 2 comments
-
Hi there, Thanks for the code, I can reproduce the problem. To just fix the error you need to change Indeed you actually already found the answer to the problem! Using This will fix the error, but then the brackets won't be plotting in the correct x position. To fix this secondary issue, just remove the line Hope this helps. library(tidyverse)
library(ggprism)
library(rstatix)
#>
#> Attaching package: 'rstatix'
#> The following object is masked from 'package:stats':
#>
#> filter
# load data
Foxp3_CD8 <- readRDS("~/Downloads/data/Foxp3_CD8.rds")
# create a stat dataframe with rstatix
Foxp3_CD8.pvalue <- Foxp3_CD8 %>%
rstatix::group_by(sample, value_type) %>%
rstatix::wilcox_test(value ~ treatment, detailed = TRUE) %>%
adjust_pvalue(method = "BH") %>%
add_significance(p.col = "p.adj") %>%
p_format("p.adj", digits = 2) %>%
rstatix::add_xy_position(
x = "sample",
#group = "treatment",
fun = "mean_sd",
scales = "free_y"
)
# generate faceted plot with p-value
Foxp3_CD8 %>%
ggplot(aes(x=sample, y=value, group = treatment), color="black") +
geom_jitter(
aes(shape = treatment),
size = 6,
position = position_jitterdodge(dodge.width = 0.5)
) +
stat_summary(
geom = "bar",
fun = mean,
color = "black",
position = position_dodge(width =0.5),
fill = NA,
size = 1.5,
width = 0.5
) +
stat_summary(
geom = "errorbar",
fun.min = function(.x){mean(.x) - sd(.x)},
fun.max = function(.x){mean(.x) + sd(.x)},
position = position_dodge(width =0.5),
width = 0.2,
) +
scale_shape_manual(values = c(16, 1)) +
facet_wrap(~ value_type, scales = "free") +
theme_prism() +
theme(axis.title.x = element_blank()) +
add_pvalue(Foxp3_CD8.pvalue,
xmin = "xmin",
xmax = "xmax",
label = "P = {p.adj}",
bracket.shorten = 0.1
) Created on 2022-08-28 by the reprex package (v2.0.1) |
Beta Was this translation helpful? Give feedback.
-
Hi Charlotte, Thank you very much for your help!!! And thank you very much for your explanation about how ggplot aes arguments are inherited in add_xy_position()! Best wishes, Jian |
Beta Was this translation helpful? Give feedback.
-
Hi Charlotte @csdaw ,
Thank you very much for producing ggprism! It's such a fantastic tool for generating prism-style plots!
I produced a plot successfully before add_pvalue, but ran into this "
Error in FUN(X[[i]], ...) : object 'treatment' not found
" after trying to add pvalues. Most perplexingly, the error is caused by a variable "treatment", which is not involved in the p-value data frame for the "test
" argument. It's a variable fed to theaes()
in ggplot. I read the vignette multiple times but couldn't figure out why this error occurs. I also randebugonce(add_pvalue)
and the function ran ok. Can I ask for your help to figure out what the problem is please?This is the data and code I used:
data.zip
Attached here is the error message:
Here is the plot that was successfully produced without add_pvalue():
Thank you very much!
Best wishes,
Jian
Beta Was this translation helpful? Give feedback.
All reactions