Run pairwise comparisons and add significance labels
pairwise_comparisons <- df_long %>%
group_by(Concentration) %>%
pairwise_t_test(Value ~ Peptide_Size, p.adjust.method = "bonferroni",
ref.group = "IC")%>%
add_y_position(ref.group = "IC")
#pairwise_comparisons <- pairwise_comparisons %>%
#add_xy_position()
pairwise_comparisons
## # A tibble: 8 × 12
## Concentration .y. group1 group2 n1 n2 p p.signif p.adj
## <fct> <chr> <chr> <chr> <int> <int> <dbl> <chr> <dbl>
## 1 150 Value IC <3 KDa 2 2 1.82e-4 *** 7.28e-4
## 2 150 Value IC >10 - <30 Kda 2 2 4.91e-5 **** 1.97e-4
## 3 150 Value IC 3-5 KDa 2 2 2.01e-4 *** 8.03e-4
## 4 150 Value IC 5-10 KDa 2 2 9.92e-5 **** 3.97e-4
## 5 300 Value IC <3 KDa 2 2 3.8 e-5 **** 1.52e-4
## 6 300 Value IC >10 - <30 Kda 2 2 6.43e-6 **** 2.57e-5
## 7 300 Value IC 3-5 KDa 2 2 4.31e-5 **** 1.72e-4
## 8 300 Value IC 5-10 KDa 2 2 1.84e-5 **** 7.37e-5
## # ℹ 3 more variables: p.adj.signif <chr>, y.position <dbl>, groups <named list>
Plot with significance bars
p <- ggplot(df_long, aes(x = Peptide_Size, y = Value)) +
geom_bar(stat = "summary", fun = "mean", position = position_dodge(width = 0.8), width = 0.6) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position = position_dodge(width = 0.8), width = 0.25) +
facet_wrap(~Concentration, scales = "free") +
theme_minimal() +
theme(legend.position = "none") + # Remove the legend
labs(x = "Peptide Size", y = "Mean % Infected Cells") +
stat_pvalue_manual(
pairwise_comparisons,
label = "p.adj.signif",
tip.length = 0
)
# Print the plot
print(p)

library(ggplot2)
library(dplyr)
# Assuming pairwise_comparisons is already created and in the correct format
# And df_long is already prepared with 'Concentration' and 'Peptide_Size' as factors
# Define custom labels for the facets
my_labels <- c(`150` = "A)", `300` = "B)")
p <- ggplot(df_long, aes(x = Peptide_Size, y = Value)) +
geom_bar(stat = "summary", fun = "mean", position = position_dodge(width = 0.8), width = 0.6) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position = position_dodge(width = 0.8), width = 0.25) +
facet_wrap(~Concentration, scales = "free", nrow = 2, labeller = labeller(Concentration = my_labels)) + # Use custom labels
theme_minimal() +
theme(legend.position = "none") + # Remove the default strip text
labs(x = "Peptide Size", y = "Mean % Infected Cells") +
stat_pvalue_manual(pairwise_comparisons
, label = "p.adj.signif", tip.length = 0)
# Print the plot
print(p)

library(ggplot2)
library(dplyr)
# Assuming pairwise_comparisons is already created and in the correct format
# And df_long is already prepared with 'Concentration' and 'Peptide_Size' as factors
# Define custom labels for the facets
my_labels <- c(`150` = "A)", `300` = "B)")
barplotfacts <- ggplot(df_long, aes(x = Peptide_Size, y = Value)) +
geom_bar(stat = "summary", fun = "mean", position = position_dodge(width = 0.8), width = 0.6) +
geom_errorbar(stat = "summary", fun.data = "mean_se", position = position_dodge(width = 0.8), width = 0.25) +
facet_wrap(~Concentration, scales = "free", nrow = 2, labeller = as_labeller(my_labels)) + # Use custom labels
theme_pubr() +
theme(legend.position = "none",
strip.text = element_text(face = "bold", hjust = 0, size = 12), # Customize facet labels
strip.background = element_blank()) + # Remove the background of labels
labs(x = "Peptide Size", y = "Mean % Infected Cells") +
stat_pvalue_manual(pairwise_comparisons, label = "p.signif", tip.length = 0)
# Print the plot
print(barplotfacts)

#ggsave("combined_plotsflowcyt.b", width = 12, height = 14, dpi = 300)