简体   繁体   中英

Plotting a table in R

I'm using the table function to display results with a confusion matrix of kNN/SVM classification.

Example:

svmE1071 <- function(x,y,type) {
  library(e1071)

  (...)

  confTab <- table(pred=pred, true=y[,1])
  return(confTab)
}

> myKknn(y, yUnknown)

        unknown
  yWohn1       6
  yFlur1      18
  yBad1       12
> svmE1071(y, yUnknown, "linear")
        true
pred     unknown
  yWohn1       3
  yFlur1      25
  yBad1        8
> svmE1071(y, yUnknown, "polynomial")
        true
pred     unknown
  yWohn1       8
  yFlur1      20
  yBad1        8
> svmE1071(y, yUnknown, "radial")
(...)

How can I generate one barplot with multiple confusion matrices (like grouped barplot) in R like this?

      yWohn1 xxxx
 kNN  yFlur1 xxxxxxxxxxxxxxx
      yBad1  xxxxxxxx

      yWohn1 x
 SVMl yFlur1 xxxxxxxxxxxx
      yBad1  xxxxxxxxxxx

 (...)

First you need to assign your tables to some variable:

table1 <- svm(...)
table2 <- svm(...)
...

Then you can combine them with cbind:

allTables <- cbind(table1, table2, ...)

And then use barplot:

barplot(allTables, beside=TRUE, names=c("SVN","kNN"))

And see ?barplot for further info.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM