Home > OS >  How to change colours on geom_signif in ggplot2
How to change colours on geom_signif in ggplot2

Time:09-17

I've made a ggplot, coloured by the hours of incubation. When I add significance bars using geom_signif, they are all coloured by the first colour, here pink. Ideally I'd like to be able to choose the colour of the significance bars, so i can indicate which incubation time they refer to. Or if that's not possible, how would I make them black?

  ggplot(data = data, mapping = aes(y = Fluorescence, x = Treatment, colour = Hours))   
  geom_boxplot(outlier.shape = NA)   
  geom_jitter(position = position_jitterdodge(jitter.width = 0.3, jitter.height = 0), alpha = 0.4)  
    theme(axis.text.x = element_text(angle = 60, hjust = 1))   
    xlab("Treatment")  
    ylab("Mean fluorescence")  
    ggtitle("C6/36")  
    geom_signif(y_position = c(5.8,6.3,2.5,2,1.5,0.5,1), 
                xmin = c(2,3,2,2.8,1.8,1.8,2.8),
                xmax = c(3,4,4,10,3.8,2.8,3.8),
                annotations = c("****","****","ns","****","****","ns","**"),
                textsize=3.5)

enter image description here

CodePudding user response:

If you set the color mapping only to the boxplot geom, coloring will only applied to this particular geom:

library(tidyverse)
library(ggsignif)

iris %>%
  mutate(group = Species %in% c("setosa", "versicolor")) %>%
  ggplot(aes(group, Sepal.Length))  
  geom_boxplot(aes(color = Species))  
  geom_jitter(aes(color = Species))  
  geom_signif(comparisons = list(c("TRUE", "FALSE")))

Created on 2021-09-14 by the reprex package (v2.0.1)

  • Related