1

我正在尝试将显着性星号(* 或 ** 或 ***)与带有位置闪避的几何点图的点对齐,以使用 ggplot2 指示值的显着性。我找不到任何类似问题的类似问题和答案。

这是数据框'df':

df<-data.frame(conc=c(1,10,100,1, 10,100,1, 10, 100), 
            mean=c( 0.9008428,0.8278645,0.7890388,0.9541905,
                         0.8537885,0.8212504,1.3828724,0.7165685, 0.7985398), 
            Treatment=c("A","A","A","B", "B", "B","C","C", "C"),
  upper =c(1.0990144, 0.9505348, 0.8273494, 1.0389074, 0.9227461, 0.9657371,    1.6864420, 0.7401891, 0.9046951),
  lower=c(0.7026713, 0.7051941, 0.7507282, 0.9528077, 0.7848309, 0.6767638, 1.0793029, 0.6929479, 0.6923846),
            p.value=c(0.0003, 0.6500, 1,0.02,0.0400,
                    0.3301,0.100,0.023, 0.05))

我用自动星号制作了一个图,但它并没有按照我想要的方式对齐,我相信这是因为position_dodge,但我在一个集中有太多点,所以我必须使用它(给定数据框是最小的)。

legend_title <- "Treatment"
breaks_y =c(0, 0.25, 0.5, 0.75, 1, 1.25, 1.5)
breaks = c(1, 10, 100) 

df$Label <- NA
df$Label[df$p.value<0.001]<-'***'
df$Label[df$p.value<0.01 & is.na(df$Label)]<-'**'
df$Label[df$p.value<0.05 & is.na(df$Label)]<-'*'

ggplot(df, aes(x = conc, y = mean, color = Treatment)) +
geom_errorbar(aes(ymax = upper, ymin = lower, width = 0),position = position_dodge(width=0.5)) + 
geom_point(aes(shape = Treatment,  fill = Treatment), size = 4, position = position_dodge(width=0.5)) +
geom_text(aes(label = Label),size = 4, position = position_dodge(width =0.5), color = "black") +
scale_shape_manual(values = c(22, 21, 23)) + 
scale_color_manual(values=c('blue','coral1', 'darkgreen' )) +
scale_fill_manual(values=c('blue','coral1', 'darkgreen')) +
labs(x = "Concentration (\u03BCM)", y = "Abs", title = "Viability", fill = "Treatment") +  
  scale_x_continuous(trans="log10", limits = c(0.5, 170), breaks = breaks) +
  scale_y_continuous(limits = c(0, 1.5), breaks = breaks_y) +
  theme_light() +
  ggpubr::rotate_x_text(angle = 70) +
  theme(axis.text = element_text(size = 12, face = "bold"),
    axis.title.y = element_text(size = 12, face ="bold"),
    axis.title.x = element_text(size = 12, face ="bold"))

在此处输入图像描述

如何将星号自动对齐到正确点的正上方position_dodge

4

0 回答 0