I am generating a bar graph to show mutation frequency by dose for a specific dataset. Underneath the bar chart I would like to include a colour block type legend that corresponds to the dose of each bar. I have included a figure (made using excel with different data) that shows exactly what I would like to achieve (see below). enter image description here
I have come across a similar question which generates colour blocks based on a specific size (see below) however, I am looking to have one that will adjust based on the number of samples (columns) in the dataset and is associated with the dose column.
ggplot: Is there a way to add a color coded bar annotation to the right of the y-axis?
I have included my current code for this here, along with the associated data and current plot.
MF_sample <- read.table(file = "SamplesData.txt", header = TRUE)
MF_by_sample<-ggplot(MF_sample, aes(x=sample, y=MFmin, fill=factor(dose))) +
geom_col() +
scale_fill_manual("Dose (mg/kg-bw/day)", values = c("0" = "#33ffff", "1" = "#00ccff", "2"="#3399ff",
"5" = "#000066")) +
theme_classic() +
theme(text = element_text(size = 11, family="calibri")) +
scale_x_discrete (limits=MF_sample$sample) +
scale_y_continuous(expand = c(0,1e-9))
#Data:
sample dose MFmin MFmax
1 Sample1 0 1.89e-07 2.38750e-07
2 Sample2 0 2.89e-07 2.46467e-07
3 Sample3 1 3.89e-07 3.04626e-07
4 Sample4 1 5.89e-07 1.01960e-07
5 Sample5 1 7.89e-07 1.04370e-07
6 Sample6 2 8.89e-07 1.98602e-07
7 Sample7 2 9.89e-07 1.77643e-07
8 Sample8 2 1.89e-07 1.94386e-07