Я пытаюсь добавить p значимых значений в парный ggplot с 2 условиями (2 переменные с 2 уровнями), более чем с 2 группами до и после измерений. Я попытался запустить этот код R с функциями stat_compare и geom_signif, но безрезультатно. Комментарии и предложения будут по-настоящему оценены. Я dput () образец моего фрейма данных ниже (df). Заранее большое спасибо за все ваши комментарии и предложения.
Желаемые результаты представляют собой сочетание этих двух изображений, где на рис. 1 представлена эстетика, а на рис. 2 - результат сюжета
R код:
#Levels
df$Demineralization <- factor(df$Demineralization, levels = c("Before", "After"))
df$GFPimg <- factor(df$GFPimg, levels = c("WT", "HT", "MT"))
#Check
levels(df$Demineralization)
levels(df$GFPimg)
# P values label list:
dfp01 <- list(c("Before","After"))
dfp02 <- list(c("HT","MT"), c("MT","WT"), c("HT","WT"))
Pairwise.test <-
df %>%
group_by(GFPimg, Cond, Temp) %>%
pairwise_t_test(
Mean ~ Demineralization, paired = TRUE,
p.adjust.method = "bonferroni"
)
Pairwise.test
# ggplot
df %>%
ggplot(., aes(GFPimg , Mean, color= Demineralization , fill=Demineralization)) +
geom_dotplot(binaxis = "y", stackdir = "center", alpha = .5, dotsize = .8) +
geom_line(aes(group=ID), colour="gray", linetype="11") +
geom_boxplot(varwidth = F, size = .2, alpha = .5, width= 0.5, outlier.color = "blue", outlier.fill = "red", outlier.size = 2, outlier.shape = NA) + #Na to hide outlier
facet_grid(Temp ~ Cond) +
scale_y_continuous(limit = c(0, 120), breaks=seq(0,120,20))+
theme(legend.position="bottom") +
stat_compare_means(aes(label= "p.signif"), label.x = 0.7, label.y = 0, size = 2.5, method = "t.test", paired = T) +
stat_compare_means(comparisons = dfp01, label = "p.signif", size= 2.5, method = "t.test", paired = T)
#Alternatively
geom_signif(comparisons = list(c("Before", "After")),
map_signif_level=TRUE, size = .3, textsize = 3, color="black" )
Пример кадра данных df:
df <- structure(list(ID = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54),
GFPimg = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L), .Label = c("HT", "MT", "WT"), class = "factor"),
Cond = structure(c(1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L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 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("L", "R"), class = "factor"),
Mean = c(62.435, 64.537, 102.447, 92.608, 103.277, 104.711, 67.017, 61.748, 68.921, 59.962, 63.368, 60.435, 69.54, 67.886, 51.71, 50.291, 50.881, 54.865, 80.538, 84.05, 92.223, 87.337, 90.444, 90.728, 29.951, 28.574, 30.896, 30.399, 29.773, 30.715, 31.498, 30.385, 99.004, 83.644, 95.962, 83.451, 22.649, 22.5, 53.066, 51.368, 55.459, 57.203, 54.444, 58.504, 76.518, 95.81, 23.43, 24.736, 28.86, 28.347, 28.386, 29.319, 58.017, 63.064, 80.293, 89.194, 70.52, 63.989, 71.436, 59.379, 75.986, 80.22, 71.583, 76.589, 77.138, 95.998, 77.193, 71.384, 75.614, 83.061, 73.062, 71.833, 71.83, 55.783, 77.376, 64, 96.14, 99.876, 40.972, 53.465, 36.25, 47.626, 40.619, 39.697, 34.34, 36.855, 77.131, 75.35, 67.014, 58.811, 39.237, 49.357, 74.333, 79.921, 62.631, 63.119, 60.207, 65.171, 77.563, 82.078, 39.115, 45.988, 42.65, 55.806, 33.534, 41.271, 62.359, 67.092),
Demineralization = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("After", "Before"), class = "factor")), class = "data.frame", row.names = c(NA, -108L))