-1

My issue is the following. I use ROCR package to plot data. performance function returns an object that I pass to plot the data like this:

example <- performance(prediction1,"tpr","fpr")
plot(example,col="red")

I want to add another performance object to this plot, but lines function accepts x and y coords and not an object. In fact if I do: lines(example2, col="blue") this error appears:

Error in as.double(y) : cannot coerce type 'S4' to vector of type 'double'**

Calimo
  • 7,510
  • 4
  • 39
  • 61
Will Arrow
  • 31
  • 6
  • 2
    Maybe you want to `plot` the 2nd `performance` object by using `plot(example2, add = TRUE)`? Check here for more info: https://stackoverflow.com/questions/14085281/multiple-roc-curves-in-one-plot-rocr – AntoniosK Aug 24 '18 at 17:06
  • Thank a lot, it work :); there is a way to giva a name to a line using plot with add=T ?? – Will Arrow Aug 24 '18 at 17:17
  • 1
    You mean to add a legend somewhere in the plot? You can check this: http://www.sthda.com/english/wiki/add-legends-to-plots-in-r-software-the-easiest-way – AntoniosK Aug 24 '18 at 17:20
  • I pass an object to plot, in this case the object is "example". the plot is a list of 4 element then the plot has 4 lines. I want to use different line types for every line (1 -> point; 2->point and lines,....). How can i do this passing a list of 4 element???? – Will Arrow Aug 24 '18 at 18:00
  • 1
    I think you need to post that as a new question. Please, be specific with what data you have (i.e. post specific example) and show/describe your ideal output. – AntoniosK Aug 24 '18 at 18:02
  • @Will Arrow, could you provide in your question the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve)." – Artem Sep 22 '18 at 12:10

1 Answers1

0

You can add new line with add = TRUE as plot argument:

library(ROCR)
data(ROCR.simple)

prediction1 <- prediction( ROCR.simple$predictions, ROCR.simple$labels)
example1 <- performance(prediction1,"tpr","fpr")
plot(example1, col="red")
example2 <- performance(prediction1, "sens", "spec")
plot(example2, col="blue", add = TRUE)

plots

Artem
  • 3,304
  • 3
  • 18
  • 41