Given such data:
#Cutpoint SN (1-PPV)
5 0.56 0.01
7 0.78 0.19
9 0.91 0.58
How can I plot ROC curve with R that produce similar result like the
attached
?
I know ROCR package but it doesn’t take such input.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you just want to create the plot (without that silly interpolation spline between points) then just plot the data you give in the standard way, prepending a point at (0,0) and appending one at (1,1) to give the end points of the curve.
To explain the code: The first
plot()call sets up the plotting region, without doing an plotting at all. Note that I force the plot to cover the range (0,1) in both axes. Thepar()call tells R to plot axes that cover the range of the data – the default extends them by 4 percent of the range on each axis.The next line,
with(dat, lines(....))draws the ROC curve and here we prepend and append the points at (0,0) and (1,1) to give the full curve. Here I usetype = "o"to give both points and lines overplotted, the points are represented by character 25 which allows it to be filled with a colour, here black.Then I add labels to the points using
text(....); theposargument is used to position the label away from the actual plotting coordinates. I take the labels from thecutpointobject in the data frame.The
abline()call draws the 1:1 line (here the0, and1mean an intercept of0and a slope of1respectively.The final line resets the plotting parameters to the defaults we saved in
opprior to plotting (in the first line).The resulting plot looks like this:
It isn’t an exact facsimile and I prefer the plot using the default for the axis ranges(adding 4 percent):
Again, not a true facsimile but close.