'Change outliers from black to colour in grouped box plot in ggplot2

I have a grouped box plot in which I want to change the outlier dots from the default of black to the colour of the boxes keeping everything else the same. There is a previous thread that provides a solution for this for a standard box plot that I am able to implement.

Coloring boxplot outlier points in ggplot2?

However, I want to do it for a grouped box plot.

Below is some example data and code for the grouped box plot.

|ID |Time |Metabolite | Concentration|
|:--|:----|:----------|-------------:|
|1  |1    |A          |            40|
|1  |1    |B          |            36|
|1  |1    |C          |            28|
|1  |2    |A          |            13|
|1  |2    |B          |           150|
|1  |2    |C          |            32|
|1  |3    |A          |            45|
|1  |3    |B          |            15|
|1  |3    |C          |            15|
|2  |1    |A          |             7|
|2  |1    |A          |             9|
|2  |1    |B          |           236|
|2  |1    |C          |            33|
|2  |2    |A          |            33|
|2  |2    |B          |            48|
|2  |2    |C          |            39|
|2  |3    |A          |            15|
|2  |3    |C          |           126|
|3  |1    |A          |            13|
|3  |1    |B          |            41|
|3  |1    |C          |            37|
|3  |2    |A          |             3|
|3  |2    |B          |           218|
|3  |2    |C          |            27|
|3  |3    |A          |             7|
|3  |3    |B          |            27|
|3  |3    |C          |             3|
|4  |1    |A          |             4|
|4  |1    |B          |             7|
|4  |1    |C          |            33|
|4  |2    |A          |           133|
|4  |2    |B          |             4|
|4  |2    |C          |            10|
|4  |3    |A          |           122|
|4  |3    |B          |            27|
|4  |3    |C          |            14|
|5  |1    |A          |             7|
|5  |1    |B          |            22|
|5  |1    |C          |            43|
|5  |2    |A          |             3|
|5  |2    |B          |             6|
|5  |2    |C          |           158|
|5  |3    |A          |            48|
|5  |3    |B          |             7|
|5  |3    |C          |            24|
|6  |1    |A          |            15|
|6  |1    |B          |            30|
|6  |1    |C          |            15|
|6  |2    |A          |            27|
|6  |2    |B          |           187|
|6  |2    |C          |             9|
|6  |3    |A          |            31|
|6  |3    |B          |            40|
|6  |3    |C          |            41|
|7  |1    |A          |            37|
|7  |1    |B          |            30|
|7  |1    |C          |            28|
|7  |2    |A          |           142|
|7  |2    |B          |            40|
|7  |2    |C          |             7|
|7  |3    |A          |            45|
|7  |3    |B          |             3|
|8  |3    |C          |            45|
|8  |1    |A          |            34|
|8  |1    |B          |             8|
|8  |1    |C          |            46|
|8  |2    |A          |           167|
|8  |2    |B          |            25|
|8  |2    |C          |            34|
|8  |3    |A          |            27|
|9  |3    |B          |            28|
|9  |3    |C          |            36|
|9  |1    |A          |            44|
|9  |1    |B          |            26|
|9  |1    |C          |            20|
|9  |2    |A          |            11|
|9  |2    |B          |            18|
|9  |2    |C          |           176|
|9  |3    |A          |             1|
|9  |3    |B          |            40|
|9  |3    |C          |            10|
|10 |1    |A          |             8|
|10 |1    |B          |            49|
|10 |1    |C          |           193|
|10 |2    |A          |            13|
|10 |2    |B          |            13|
|10 |2    |C          |            28|
|10 |3    |A          |            50|
|10 |3    |B          |            47|
|10 |3    |C          |            46|
|11 |1    |A          |            21|
|11 |1    |B          |            34|
|11 |1    |C          |            28|
|11 |2    |A          |            13|
|11 |2    |B          |            32|
|11 |2    |C          |            47|
|11 |3    |A          |            15|
|11 |3    |B          |            42|
|11 |3    |C          |             9|

ggplot(df, aes(x=Time, y=Concentration, fill=Metabolite)) +
  geom_boxplot() 


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source