I would like to have different panels of colors depending on the species class. I managed to change the legend correctly to have the right color panel for each class.
The problem is: the colors in the graph are not identical to the ones in the legend. Do you have any idea to fix it?
I did this code :
ggplot(ABUNDANCE, aes(x = Season, y = meanSEQ, fill = Scientific.name)) +
geom_bar(stat = "identity", position = "dodge", width = .6) +
labs(x = "", y = expression("Log10 (Mean number of sequences) ")) +
facet_wrap(~Data.type, ncol = 1, strip.position = "top") +
scale_fill_manual(
values = c(
brewer.pal(3, "Blues")[-1], brewer.pal(9, "Reds")[-1],
brewer.pal(6, "Oranges")[-1], brewer.pal(5, "OrRd")[-1],
brewer.pal(6, "BuGn")[-2], brewer.pal(6, "Greens")[-1]
),
drop = FALSE, name = "Plankton species",
labels = c(
"Mnemiopsis leidyi", "Obelia sp.", "Calanus finmarchicus",
"Calanus helgolandicus", "Centropages hamatus", "Centropages sp.",
"Centropages typicus", "Evadne nordmanni", "Euterpina acutifrons",
"Luidia sarsi", "Metridia lucens", "Metridia sp.", "Microcalanus sp.",
"Oithona similis", "Oithona sp.", "Paracalanus parvus", "Penilia avirostris",
"Podon leuckartii", "Temora longicornis", "Chaetoceros curvisetus",
"Chaetoceros danicus", "Chaetoceros sp.", "Coscinodiscus wailesii",
"Ditylum brightwellii", "Protoperidinium divergens", "Rhizosolenia setigera",
"Skeletonema marinoi", "Tripos sp."
)
) +
scale_x_discrete(
expand = c(0, .6),
limits = c("Summer", "Fall", "Winter", "Spring"),
labels = c("Summer 2021", "Fall 2021", "Winter 2022", "Spring 2022")
) +
scale_y_log10() +
theme_bw() +
theme(legend.title.align = 0.5, legend.text = element_markdown())