Possible to position an image to be in the right side of the plot, regardless of whether there is a legend or not?

When I add an image with xref="paper", x=1, xanchor="right", then if there is no legend the image is actually placed at the righstmost of the plot.

But if there is a legend on the right side, it seems like the legend doesnโ€™t count as part of the plot, so the image will be to the left of the legend.

I know that I can manually move it by specifying a larger value than x=1, but the legend can be of different widths depending on the label values, so I wanted to know how can I make the image always position to the right of the entire plot area?