vermicellion
vermicellion

Reputation: 389

custom color for each group + category combination raincloud plot

I have a raincloud plot: raincloud plot with default colors

but I would like each combination of TL group and yr to be a different color, as one can do in base boxplot(): boxplot with wanted different colors

I have tried using the following code for the raincloud plot:

Y_C_rain= ggplot(yct_rain, aes(y=d13C, x=lengthcat,fill = yr,color=yr)) +
   geom_flat_violin(position = position_nudge(x = .2, y =0), alpha = .8)+
   geom_point(aes(y = , color = yr), 
             position = position_jitter(width = .05), size = 2, alpha = .5) +
   geom_boxplot(width = .3, guides = FALSE, outlier.shape = NA, alpha = 0, notch = FALSE) +
   stat_summary(fun= mean, geom = "point", shape = 21, size = 3, fill = "black") +
   scale_y_continuous (limits = c(-35,-10),expand = c(0,0),breaks=seq(-35,-10,5)) +
   ylab("d13C") + xlab("TL group") +
   ggtitle("YCT d13C") +
   theme_bw() +
   scale_colour_discrete(my_clrs_yct)+
   scale_fill_discrete(my_clrs_yct)
Y_C_rain

I know that the colors in the rain plot will need to be coded with some variant of scale_fill_xxx but I am hitting a road block since it appears that each point also needs to have its own color. Therefore the variations of scale_fill_xxx with only 6 individual colors listed is not working.

Upvotes: 0

Views: 2095

Answers (1)

user12728748
user12728748

Reputation: 8506

Do you want something like this?

library(dplyr)
library(data.table)
library(ggplot2)
# used geom_flat_violin from https://gist.github.com/dgrtwo/eb7750e74997891d7c20

my_clrs_yct <- c("#404040", "#407a8c", "#7a7a7a", "#404f86", "#a6a6a6", "#3e1451")

## used storms from dplyr as reproducible example
data("storms")
setDT(storms)
storms[, season:= factor(ifelse(month <=6, "Q12", "Q34"))]

ggplot(storms, aes(x=status, y=pressure, color=interaction(status, season), 
                   fill=interaction(status, season))) + 
    geom_point(aes(color = interaction(status, season)), 
               position = position_jitterdodge(
                   jitter.width=.1, dodge.width=.25), size = 2, alpha = .5)+
    geom_flat_violin(position = position_nudge(x = .5, y =0), alpha = .5)+
    geom_boxplot(width = .3, guides = FALSE, outlier.shape = NA, alpha = 0)+
    stat_summary(fun = mean, geom = "point", shape = 21, size = 3, 
                 fill = "black", position = position_nudge(x = c(-.075,.075), y =0)) +
    theme_bw() +
    scale_colour_manual(values=my_clrs_yct) +
    scale_fill_manual(values=my_clrs_yct)

Upvotes: 1

Related Questions