Hello,
I am trying to understand how I can get a different background color based on a variable in Box plot.
Currently, I am using the below ggplot2 code for the box plot but it will be great to change the background color based on a variable.
p <- ggplot(data = data, aes(x=SampleType, y=value,fill=SampleType)) +
theme_bw() +
theme(
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.title = element_text(vjust = -8.5,hjust = 0.1),
line=element_line(size=1),
axis.text.x = element_text(size = 10, face ="bold", hjust = 0.5, colour = "black"),
axis.text.y = element_text(size = 12, face ="bold", hjust = 0.5, colour = "black"),
axis.ticks.x = element_blank()) +
theme(strip.background=element_rect(fill="white")) +
theme(strip.text=element_text(color="black",face="bold", size =14)) +
geom_boxplot(aes(fill=SampleType),outlier.colour = NA)
p + facet_wrap(.~name,scales="free_y", ncol = ncol)
I have also attached the example figure that has a different background color.
Many thanks,
Fig.pdf (15.7 KB)
-->