Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push plot legend up slightly in R

Tags:

plot

r

legend

I have an ECDF plot I've created with R and it has a legend in the bottom right hand corner. The problem I'm having is that the faint grey dashed horizontal line that the ECDF plot places at 0.0 is overlapping the last item in my legend. Like so:

enter image description here

At the moment I'm creating the legend with:

legend("bottomright",c("Original","Minus 30 minutes"),col=c("black","red"),lty=c("dashed","dotted"))

Is there a way to simply push the legend up a little to avoid the overlap problem? An ideal solution would be one that programatically detects the overlap and corrects for it appropriately, but failing this, some empirically determined number of pixels offset would probably suffice.

like image 808
Bryce Thomas Avatar asked Dec 03 '25 11:12

Bryce Thomas


2 Answers

You probably want to use inset=c(0,.01) (or some other value) in your call to legend

like image 125
Ricardo Saporta Avatar answered Dec 06 '25 01:12

Ricardo Saporta


legend(x=1e+04, y=0.2, c("Original","Minus 30 minutes"), 
                       col=c("black","red"), 
                       lty=c("dashed","dotted"))
like image 27
IRTFM Avatar answered Dec 06 '25 01:12

IRTFM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!