But how can I avoid this hard-coding by automating and generalizing this so I can more easily make many plots where the data have different ranges and I need to change the legend to show different conditions?