我正在嘗試向堆疊條形圖添加多個 p 值。我可以使用以下代碼將單個 p 值添加到我的資料中:
library(tidyverse)
library(ggprism)
library(rstatix)
RDT_Pos_genus_pval <- table(RDT_genus_ratio$Ag_RDT, RDT_genus_ratio$Genus_Cytb) %>% ##filtered to one group for example purposes
fisher.test() %>%
.$p.value %>%
signif(3)
Pos_genus_pval <- data.frame(
group1 = "Mastomys",
group2 = "Praomys",
label = RDT_Pos_genus_pval,
y.position = 1.05)
RDT_genus_ratio_bar <- ggplot(RDT_genus_ratio)
geom_bar(mapping = aes(x = Genus_Cytb, fill = Ag_RDT), position = "fill")
labs(y = "Percentage", x = "Genus")
scale_y_continuous(labels = scales::percent, guide = "prism_offset_minor")
scale_x_discrete()
scale_fill_discrete(name = "Antigen Status", labels = c("FALSE" = "Ag -", "TRUE" = "Ag "))
theme_classic()
theme(aspect.ratio = 2/1.5, plot.title = element_text(hjust = 0.5, size = 16),
axis.text.y = element_text(size = 12, vjust = -0.2), axis.text.x = element_text(size = 10),
axis.title = element_text(size = 12), axis.title.x.bottom = element_text(size = 12, vjust = 0.5))
add_pvalue(Pos_genus_pval, label = "p = {label}")

但是,我想為所有三組添加成對費舍爾檢驗。我知道使用rstatix包我應該能夠通過為此專門創建一個資料框來做到這一點,然后將其添加Pos_genus_pval到add_pvalue行中。但是,我一直被困在add_y_position part(見下文)
asdf <- table(RDT_genus_ratio$Ag_RDT, RDT_genus_ratio$Genus_Cytb) %>%
pairwise_fisher_test()
# A tibble: 3 x 6
group1 group2 n p p.adj p.adj.signif
* <chr> <chr> <int> <dbl> <dbl> <chr>
1 Mastomys Praomys 316 4.14e- 1 4.14e- 1 ns
2 Mastomys Rattus 491 7.44e-18 2.23e-17 ****
3 Praomys Rattus 209 1.29e- 2 2.58e- 2 *
asdf <- table(RDT_genus_ratio$Ag_RDT, RDT_genus_ratio$Genus_Cytb) %>%
pairwise_fisher_test() %>%
add_y_position(formula = group1 ~ group2) ##this line is where I'm getting stuck
Error in add_y_position(., formula = group1 ~ group2) :
data and formula arguments should be specified.
我一直在嘗試遵循
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/335797.html
