0

I have a computed confusion matrix from google earth engine that I would like to use in r to derive a plot. how do I manually enter the confusion matrix and plot in R?. This is the confusion matrix:

1:[141,17,3,6,0,0,39,2] 2:[9,287,0,6,17,0,51,0] 3:[31,1,8,14,9,0,29,1] 4:[2,2,0,179,24,0,23,30] 5:[1,10,0,17,78,0,69,1] 6:[0,0,0,15,3,0,3,16] 7:[22,41,3,12,45,0,380,0] 8:[12,0,3,60,1,0,4,204]

1 Answer 1

0

Using the image function, you can:

# import your data values
z = c(141,17,3,6,0,0,39,2,
      9,287,0,6,17,0,51,0,
      31,1,8,14,9,0,29,1,
      2,2,0,179,24,0,23,30,
      1,10,0,17,78,0,69,1,
      0,0,0,15,3,0,3,16,
      22,41,3,12,45,0,380,0,
      12,0,3,60,1,0,4,204)

# create a matrix
z = matrix(z, ncol = 8)

# set rows and columns names
colnames(z) = c("1","2","3","4","5","6","7","8")
rownames(z) = c("1","2","3","4","5","6","7","8")

##To get the correct image plot rotation
##We need to flip the plot
image(z[,ncol(z):1], axes = FALSE)

##Add in the y-axis labels. Similar idea for x-axis.
axis(2, at = seq(0, 1, length=length(colnames(z))), labels = colnames(z))

And here is your output output

6
  • Thank you so much!, I've used the code and replaced the column and row numbers with names as well, but is there a way to get a scale to relate the values to the colors?
    – Rozy
    Sep 23 at 19:45
  • You mean like a legend?
    – Nikos
    Sep 23 at 19:47
  • yes if possible
    – Rozy
    Sep 23 at 19:49
  • There are options with ggplot2 (e.g., stackoverflow.com/questions/37897252/…). But this a question for an other topic I think
    – Nikos
    Sep 23 at 20:04
  • Also, when someone's answer solved your problem please read this gis.stackexchange.com/help/….
    – Nikos
    Sep 23 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.