0

I have used the Kohonen package in R to apply SOM to a genomics dataset I have. The SOM has 55 variables. I want to plot a subset of the codes for these variables as fanplots. For example, just using the wine dataset innate in R:

library(kohonen)
data(wines)
set.seed(7)

training <- sample(nrow(wines), 120)
Xtraining <- scale(wines[training, ])
Xtest <- scale(wines[-training, ],
           center = attr(Xtraining, "scaled:center"),
           scale = attr(Xtraining, "scaled:scale"))

som.wines <- som(Xtraining, grid = somgrid(5, 5, "hexagonal"))
plot(som.wines, type="codes")

This plots the weight of every predictor on each node as a fanplot. What I would like to do in this instance is plot say, just magnesium, ash, malic acid and flavonoids in the fanplot.

plot(som.wines, type = "property", property = som.wines$codes[,'magnesium'])

Will plot the weight for magnesium on each node.

Doing something like

plot(som.wines, type = "property", property =som.wines$codes[,c('magnesium','ash')])

Just overrides the magnesium weights with ash weights for each node.

Additionally something like:

plot(som.wines, type = "codes", property = som.wines$codes[,c('magnesium','ash')],)

Does not work either.

Any help would be very appreciated.

  • You should provide some form of [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data that we can run so we can see what you are seeing. Describe how you want to choose the subset of predictors. Right now i'm really not sure what kind of answer you are looking for. – MrFlick Sep 09 '16 at 22:10
  • Hi MrFlick, thanks for the advice - I have updated my question which should be more explanatory. – David McCoy Sep 09 '16 at 23:08

1 Answers1

0

Well, we know

class(som.wines)
# [1] "kohonen"

So the plotting method that's triggered here is kohonen:::plot.kohonen. When you set type="codes", that farms out the command to kohonen:::plot.kohcodes. Upon inspection, it only appears to use the $codes and $grid property of the object you pass it. It appears to be safe if you want to subset those values directly. For example

keep <- c("magnesium", "ash", "malic acid", "flavonoids")
xx <- som.wines
xx$codes<-xx$codes[,keep]
plot(xx, type="codes")

This produces

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295