Add a variable as legend/factor to XY-Plot / GG Plot

I can't say for sure since your example is not reproducible (you haven't provided sample data) but I think you just have to remove the quotes from this.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.