0

I want to plot a roc curve in R but with legends outside the plot. I want the axes labels to be from 0-1. So I used pty="s" but I am trying to fit the legend its not working.

par(pty="s",xpd=T, mar=par()$mar+c(0,0,0,3))

plot(g1,main="BPH vs G6", lty=1,xlab="Specificity", ylab="Sensitivity", 
     lwd=2,cex.main=2,font.axis=2,font.lab=2,cex.lab=2,cex.axis=1.2)

lines(g2, lty=1, col="red", lwd=2) 

legend(-0.1,0.8,
       legend=c("301+CN","CN"), 
       lty=c(1,1),col=c("red", "black"),cex=0.5)

This is the plot I get

I do not want the diagonal line to go outside the plot. Also, I want to increase the legend size, but by adjusting cex its not fitting here.

Triparna Poddar
  • 408
  • 1
  • 4
  • 14
  • 1
    To stop the diagonal line going outside, hold-off on changing `xpd=` at the start. Do your main plot, changing only the `mar=` argument and then call `par(xpd=TRUE)` again just before the `legend`. – thelatemail Aug 25 '20 at 02:32
  • I assume you're using the pROC package, is that correct? – Calimo Aug 25 '20 at 05:37
  • There's already a question [Plot a legend outside of the plotting area in base graphics?](https://stackoverflow.com/q/3932038/333599) with very good answers. No need to ask it again here. I'm not flagging your question as a duplicate as you have a secondary question on the legend size. Can you please update your question to focus on the legend size? As a general note, it's best to only ask one question per question. – Calimo Aug 25 '20 at 06:41
  • Yes I am using pROC package. – Triparna Poddar Aug 27 '20 at 18:15
  • Actually I did figure out how to put legend outside the plot but I had to use pty=s and using both together I couldn't figure out how to get rid of the extended diagonal line. – Triparna Poddar Aug 27 '20 at 18:17

0 Answers0