I have trouble to visualize the pattern distinction in my R! boxplot, for which I've used ggplot
& ggpattern
. I want to show the white stripes for the condition "s". But since the boxplots in the legend are white themselves, I cannot see the stripes. Therefore, I want to change the filling of the condition legend to black or grey to see the stripes. I was looking for an answer here and also in ChatGPT, but nothing helped so far. For context here is my code:
## Loading of packages
library(ggplot2)
library(readxl)
library(ggpattern)
##data input
data <- read_excel("DATA_V1_VTM_23_24.xlsx")
##boxplot formation
plot_1 <- ggplot(data=data, aes(x = tp,y = Fv_Fm, fill = genotype, group = interaction(tp, genotype, condition)))+geom_boxplot_pattern(aes(pattern = condition, pattern_fill = condition), pattern_density = 0.25, outlier.shape = NA)+scale_pattern_manual(values= c("c"="none","s"= "stripe"), guide = guide_legend(override.aes = list(pattern = c("c"="none", "s"="stripe"), pattern_fill = c("c"="black","s"="white"))))+scale_pattern_fill_manual(values=c("c"="black","s"="white"))
##show boxplot
plot_1
This is the resulting image:
My dataset is setup as follows:
group;genotype;condition;tp;rep No;Fv_Fm;Y_II;Y_NO;Y_NPQ
1;Col-0;c;15;1;0.811;0.564;0.342;0.094
1;Col-0;c;15;2;0.799;0.494;0.312;0.194
1;Col-0;c;15;3;0.74;0.326;0.325;0.349
1;Col-0;c;15;4;0.812;0.422;0.328;0.25
2;Col-0;s;15;1;0.822;0.447;0.3;0.253
2;Col-0;s;15;2;0.811;0.38;0.308;0.312
2;Col-0;s;15;3;0.803;0.319;0.352;0.329
2;Col-0;s;15;4;0.81;0.112;;
3;inv4;c;15;1;0.814;0.317;0.161;0.522
3;inv4;c;15;2;0.74;0.33;0.163;0.507
3;inv4;c;15;3;0.803;0.31;0.303;0.387
3;inv4;c;15;4;0.812;0.328;0.25;0.422
4;inv4;s;15;1;0.817;0.658;0.202;0.14
4;inv4;s;15;2;0.746;0.286;0.363;0.351
4;inv4;s;15;3;0.803;0.232;0.358;0.41
4;inv4;s;15;4;0.822;0.822;;
5;Col-0;c;30;1;0.793;0.485;0.323;0.192
5;Col-0;c;30;2;0.759;0.336;0.355;0.309
5;Col-0;c;30;3;0.793;0.460;0.321;0.219
5;Col-0;c;30;4;0.805;0.178;0.439;0.383
1;Col-0;s;30;1;0.801;0.268;0.3;0.253
1;Col-0;s;30;2;0.793;0.238;0.492;0.27
1;Col-0;s;30;3;0.788;0.222;0.43;0.348
1;Col-0;s;30;4;0.822;0.136;;
2;inv4;c;30;1;0.769;0.49;0.319;0.191
2;inv4;c;30;2;0.815;0.512;0.321;0.167
2;inv4;c;30;3;0.79;0.351;0.329;0.32
2;inv4;c;30;4;0.742;0.112;;
3;inv4;s;30;1;0.726;0.285;0.478;0.237
3;inv4;s;30;2;0.753;0.426;0.29;0.284
3;inv4;s;30;3;0.817;0.194;0.439;0.367
3;inv4;s;30;4;0.755;0.196;0.397;0.407
4;Col-0;c;45;1;0.793;0.512;0.316;0.172
4;Col-0;c;45;2;0.766;0.472;0.356;0.172
4;Col-0;c;45;3;0.782;0.469;0.31;0.221
4;Col-0;c;45;4;0.789;0.47;;
5;Col-0;s;45;1;0.74;0.035;0.971;-0.006
5;Col-0;s;45;2;0.169;0.020;0.978;0.002
5;Col-0;s;45;3;0.799;0.082;0.684;0.234
5;Col-0;s;45;4;0.814;0.115;0.504;0.381
4;inv4;c;45;1;0.798;0.331;0.21;0.459
4;inv4;c;45;2;0.754;0.6;0.243;0.157
4;inv4;c;45;3;0.76;0.329;0.265;0.406
4;inv4;c;45;4;0.763;0.336;0.361;0.303
1;inv4;s;45;1;0.472;0.025;0.953;0.022
1;inv4;s;45;2;0.785;0.069;0.826;0.105
1;inv4;s;45;3;0.797;0.101;0.699;0.2
1;inv4;s;45;4;0.801;0.801;;
I hope you can help me. Thanks in advance.
You can manually specify the colour used in the legend, for example to set it as
grey50
, addfill=grey50
to the override.aes list to give: