Selecting/Deselecting traces from code

which plotting functionality are you using ggplot2? plotly? something else ?

alternatively, if you can share a minimal reproducable example of such a plot that you want to do this to, someone here with familiarity might be able to amend it for you.