Solved – Drawing Chernoff graph in R with only four face features

I have used aplpack package faces() method in R for drawing a Chernoff graph of the following data. I would like to draw a face with only four variables a, b, c, and d in order to explain why program A is better than program B. However, the faces() method is also using these variables for several other face features. Could you please help me to draw a Chernoff face having four features with these four variables. For example: length: a, width: d, eyes: b, and nose: c. Just I wanted to distinguish face graphs of programs A and B only with these four face features, and rest of the face features should be the same between programs A and B face graphs.

prog  a   b    c    d A    0.8 7900  70  27 B    0.3 1920 393  43 

I guess the "problem" is the default behavior of R to duplicate columns/row if the required dimension is the higher than the dimension of the provided data.

Hence the fix is to set the components of the face you want to be variable explicitly and set the rest to a constant. This code snippet should illustrate this:

require(aplpack)  # a length corresponds to index 1 # d width corresponds to index 2 # b eyes corresponds to 7 and 8 # c nose  corresponds to 12 and 13  # data as specified by the OP opdat <- data.frame("a" = c(0.8, 0.3), "b"=c(7900, 1920),                      "c"=c(70, 393), "d"=c(27, 43)) rownames(opdat)<- c("A", "B") # original plot faces(opdat, face.type=0)  # now create data.frame for plotting. plotdat <- matrix(1, nrow=2, ncol=15) # all constant rownames(plotdat) <- c("A", "B") # now set only the columns aka face components of interest plotdat[, 1] <- opdat$a plotdat[, 2] <- opdat$d plotdat[, c(7.8)] <- opdat$b plotdat[, c(12, 13)] <- opdat$c  faces(plotdat, face.type=0) 

Before:

chernoff_before

After:

chernoff_after

Similar Posts:

Rate this post

Leave a Comment