On 3/29/2011 2:48 AM, meytar wrote:> Hello
> I am trying to make a graph of 10 different lines built each from 4
> different
> segments and to add a darker line that will represent the average of all
> graphs
> - all in the same plot.Actually each line is a ROC plot
> The code I'm using for plotting one line is as follows:
>
> logit.roc.plot<- function(r, title="ROC curve") {
> old.par<- par(no.readonly = TRUE); on.exit(par(old.par))
> par(xaxs="i", yaxs="i")
> plot(1 - r$spec, r$sens, xlim=c(0, 1), ylim=c(0,1), type="l",
> xlab="(1 - specificity): false positive rate",
> ylab="sensitivity: true positive rate",
> col="grey82", lwd=2);
> points(1 - r$spec, r$sens,pch=20, cex=1.5, col="grey82")
> abline(0, 1, lty=2);
> segments(1-r$spec, 1-r$spec, 1-r$spec, r$sens, lty=3)
> #text(1 - max(r$spec,na.rm=T),
> r$sens[which.max(r$spec)],r$pts[which.max(r$spec)],pos=2,cex=0.8)
> text(0, 0.9, paste("Area under ROC:",round(logit.roc.area(r),4)),
pos=4)
> title(main = title)
> }
> r[5,]=c(0,0,1,10)
> logit.roc.plot(r)
> r=r[-5,]
> text(1 - max(r$spec,na.rm=T),
> r$sens[which.max(r$spec)],r$pts[which.max(r$spec)],pos=2,cex=0.8)
>
> while r is a MATRIX (4x4) with
>
colnames=c("pts",sens","spec",iterationnumber.")
> and I have for each ROC curve a different matrix but all matrices have the
> same
> size. (They are organized as a list of 10 matrices by the size 4X4 each)
>
> Would appreciate your help in putting all ROC curves on the same plot.
> Thank you
The reason you are getting new plots each time is the plot() call in the
function. If you pull the plot initialization out of the function (so
that the limits and axis labels get set up only once), then that plot
could be replaced with a points call.
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University