图例显示不正确,'Warning: Computation failed in `stat_signif()`:' while 运行 'geom_signif' 代码

Incorrect legend display, and 'Warning: Computation failed in `stat_signif()`:' while running 'geom_signif' code

大家晚上好,

我的图表有两个主要问题。第一个是图例显示不正确的形状。它不显示均值的形状,而是显示离群值的形状 please see attached.

此外,当我尝试 运行

geom_signif(comparisons = list(c("Blank", "Vehicle - Vehicle")), map_signif_level = TRUE, colour = "#cf1b1b") 代码,I am getting the following error

不明白R要求的是什么值。一开始,我只是想可能是因为数据没有标准化,而且我使用的是小值,所以它在 y 轴上没有足够的 space 来显示 map_signif_level = TRUE,但是在另一个例子,它显示 map_signif_level = TRUE correctly。所以,我不明白为什么它有时会正确显示 my_comparisons 而有时不会。

这些是我用来生成上图的以下代码:

library(tidyverse)
library(ggplot2)
library(ggpubr)
ggplot(PhospholipaseA2NOPo1, aes( x = Drug, y = Absorbance))+
  geom_line(aes(linetype='median'),size=1)+
  geom_point(aes(shape='mean'),size=3)+
  ggtitle("Comparison of the effect of Blank, Vehicle - Vehicle, Vehicle - Nicotinic Acid, SP - Vehicle, and SP -Nicotinic Acid on microglia - Phospholipase A2 Assay ") +
  labs(x = expression(paste("Treatment")))+
       ylab(expression(paste("Absrobance " ~ "(",   A[425], " - ", A[600] ~ nm, ")"))) +
  stat_summary(fun=mean, colour="black", geom="point", 
               shape=18, size=3) + 
  geom_point() +
  scale_x_discrete(labels = c("Blank", "Vehicle- Vehicle", "Vehicle - Nicotinic Acid", "SP - Vehicle", "SP - Nicotinic Acid"))+
  stat_compare_means(label.y = 0.50,
                     label.x = 3.25)+
          geom_boxplot(fill=c("#2171B5","#DEEBF7", "#CC79A7", "#CC79A7", "#CC79A7"), width=0.2,notch = FALSE)+
  geom_signif(comparisons = list(c("Blank", "Vehicle - Vehicle")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Blank", "Vehicle - Nicotinic Acid")), map_signif_level = TRUE,  colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Blank", "SP - Vehicle")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Blank", "SP - Nicotinic Acid")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Vehicle - Vehicle", "Vehicle - Nicotinic Acid")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Vehicle - Vehicle", "SP - Vehicle")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Vehicle - Vehicle", "SP - Nicotinic Acid")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Vehicle - Nicotinic Acid", "SP - Vehicle")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("Vehicle - Nicotinic Acid", "SP - Nicotinic Acid")), map_signif_level = TRUE, colour = "#cf1b1b")+
  geom_signif(comparisons = list(c("SP - Vehicle", "SP - Nicotinic Acid")), map_signif_level = TRUE, colour = "#cf1b1b")+
                  theme_bw() +
        theme(panel.grid.major = element_line(colour = "#d3d3d3"),
              panel.grid.minor = element_blank(),
              panel.border = element_blank(), panel.background = element_blank(),
              plot.title = element_text(size = 14, face = "bold"))+
                   theme(axis.text.x = element_text(face="bold", color="#3142b0", 
                           size=8.9, angle=0),
                         axis.text.y = element_text(face="bold", color="#3142b0", 
                           size=8.9, angle=0))+
  scale_linetype_manual('Legend',values='solid')+
  scale_shape_manual('',values = 18)+
  theme(legend.spacing.y = unit(0.01, "cm"))

为了生成上图,我使用了 the following data

非常感谢您的帮助。

这将是一个不完整的答案,因为我不确定如何修复图例,但这是一个好的开始:

PhospholipaseA2NOPo1<-structure(list(Drug = structure(c(1L, 1L, 5L, 5L, 5L, 5L, 5L, 
                                       5L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 
                                       2L, 2L, 2L), .Label = c("Blank", "SP.N", "SP.V", "V.N", "V.V"
                                       ), class = "factor"), Absorbance = c(0.178155098, 0.281888047, 
                                                                            0.315468607, 0.395427286, 0.443773761, 0.274327232, 0.126408569, 
                                                                            0.160375886, 0.332019768, 0.328779358, 0.31918001, 0.202597307, 
                                                                            0.241052828, 0.332138474, 0.356656925, 0.329787758, 0.291912398, 
                                                                            0.264823437, 0.167194165, 0.176451481, 0.406376062, 0.28900749, 
                                                                            0.298281464, 0.181890255, 0.245723697, 0.350279692)), class = "data.frame", row.names = c(NA, 
                                                                                                                                                                      -26L))

library(tidyverse)
library(ggplot2)
library(ggpubr)
ggplot(PhospholipaseA2NOPo1, aes( x = Drug, y = Absorbance))+
  ggtitle("Comparison of the effect of Blank, Vehicle - Vehicle, Vehicle - Nicotinic Acid, SP - Vehicle, and SP -Nicotinic Acid on microglia - Phospholipase A2 Assay ") +
  labs(x = expression(paste("Treatment")))+
  ylab(expression(paste("Absrobance " ~ "(",   A[425], " - ", A[600] ~ nm, ")"))) +

  geom_point() +
  scale_x_discrete(labels = c("Blank", "Vehicle- Vehicle", "Vehicle - Nicotinic Acid", "SP - Vehicle", "SP - Nicotinic Acid"))+
  stat_compare_means(label.y = 0.50,
                     label.x = 3.25)+
  geom_boxplot(fill=c("#2171B5","#DEEBF7", "#CC79A7", "#CC79A7", "#CC79A7"), width=0.2,notch = FALSE)+
  stat_summary(fun=mean, colour="black", geom="point", 
               shape=18, size=3) + 
  geom_signif(comparisons = split(t(combn(levels(PhospholipaseA2NOPo1$Drug), 2)), seq(nrow(t(combn(levels(PhospholipaseA2NOPo1$Drug), 2))))), 
              map_signif_level = TRUE, colour = "#cf1b1b", step_increase = .1)+
  theme_bw() +
  theme(panel.grid.major = element_line(colour = "#d3d3d3"),
        panel.grid.minor = element_blank(),
        panel.border = element_blank(), panel.background = element_blank(),
        plot.title = element_text(size = 14, face = "bold"))+
  theme(axis.text.x = element_text(face="bold", color="#3142b0", 
                                   size=8.9, angle=0),
        axis.text.y = element_text(face="bold", color="#3142b0", 
                                   size=8.9, angle=0))+
  scale_linetype_manual('Legend',values='solid')+
  scale_shape_manual('Mean',values = )+
  theme(legend.spacing.y = unit(0.01, "cm"))

平均而言,您将统计摘要放在箱线图之前,因此它不会显示,因为箱子放在它上面。话虽如此,我不知道如何将其放入图例中,所以这就是这个答案不完整的地方。您在 geom_point(aes(shape='mean'),size=3) 中使用的技术将塑造图表上的所有点,而不仅仅是平均值,这就是我删除它的原因。至于意义,我认为问题是你告诉它根据新的 x 轴刻度而不是药物本身的实际名称来确定意义。因此,如果您将它们更改为“SP.N”而不是“SP - Nicotinic Acid”,我认为它会起作用。为了简单起见,我只添加了一行来比较所有级别。

祝你好运,希望更擅长图表的人能够对图例提供更多帮助!

解决方案

我找到了我的图例的解决方案。首先,在使用 scale_color_manual 时,我们必须添加另一个 aes 映射,以便生成任何类型的图例。所以,我又加了geom_point()geom_point(aes(colour = "Blank (50 µM of dH20)"))。然后,有了 aes 映射,我可以使用以下代码生成我的图例:

scale_color_manual(name = "Final concentrations and volumes",
                     labels = c( "Blank (50 µL of dH20)", "Vehicle - Vehicle (10µL of dH20 + 10µL of dH20)", "Vehicle -Nicotinic Acid (10µL of dH20 + 10µL of 1mM)", "Sp-Vehicle (10µL of 5µM + 10µL of dH20)", "Sp-Nicotinic Acid( 10µL of 5µM + 10µL of 1mM)"),
                     values = c("Blank (50 µL of dH20)" =  "#B2182B", "Vehicle - Vehicle (10µL of dH20 + 10µL of dH20)" = "#D6604D", "Vehicle -Nicotinic Acid (10µL of dH20 + 10µL of 1mM)" = "#F4A582", "Sp-Vehicle (10µL of 5µM + 10µL of dH20)"= "#FDDBC7", "Sp-Nicotinic Acid(10µL of 5µM + 10µL of 1mM)"= "#D1E5F0"))+

有了,我可以使用以下代码更改我的图例位置:

theme(legend.position = c(0, .97),
        legend.justification = c("left", "top"),

我还希望图例的背景是透明的,所以我使用了以下代码:

legend.background = element_rect(colour = NA, fill = NA))

结果,我得到了以下outcome

现在正在研究如何给H20加下标。我知道我可以使用 expressionbquote,但到目前为止我得到的是 like this。我想我弄乱了“*”之类的东西。