0

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

  • Please provide a [reproducible minimal example](https://stackoverflow.com/q/5963269/8107362). Especially, provide some sample data, e.g. with `dput()` and use the [reprex-package](https://reprex.tidyverse.org/). – mnist Sep 10 '21 at 13:39

1 Answers1

1

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)

danlooo
  • 10,067
  • 2
  • 8
  • 22
  • Thanks for this! However, when I try this alongside geom_jitter() I get an error that position_jitterdodge() needs an aesthetic to dodge by. – Ellen Masters Sep 14 '21 at 09:12
  • 1
    I updated my answer to work `geom_jitter` as well. Note that I resused the `color` aesthetic in `geom_jitter` again. If this is not what you want, I need more example code or explainations. – danlooo Sep 14 '21 at 09:28
  • Amazing, this works perfectly - thank you! – Ellen Masters Sep 14 '21 at 14:11