Search code examples
rplottransparencylegend

Opaque Legend Box


I was wondering how I could go about creating an opaque legend box in R for my plots? I've tried using bg="grey", but the lines on the graph are still covering the legend.


Solution

  • You have to use bg="white" (or any other color, as you already did) and you have to draw the legend after you plot the lines/points/grid/etc.

    For example:

    plot(...)
    lines(...)
    grid(...)
    legend(...) # legend has to be the last command!