Search code examples
rsom

How can I do a multiple plot with a somSC type graph?


I'm sure this is an easy one, but I dont know why this code cannot plot two graphs in the same window.

nfil=5
ncol=5
set.seed(850)
som <- trainSOM(x.data=datasom[3:8], 
                dimension=c(nfil,ncol),
                nb.save = 100,
                verbose=TRUE)
#  SUPERCLUSTERS
num.grupos=4
som.sc <- superClass(som, k=num.grupos)
###  PLOTEO SOM
par(mfrow=c(1,2))
plot(som.sc, plot.var=FALSE)
# observaciones de cada neurona
counts<-as.vector(som.sc$som$clustering)
kounts<-c(0)
for (i in 1:(nfil*ncol)) {
  kounts[i]=0
}
for (i in 1:(length(counts))) {
  kounts[counts[i]]=kounts[counts[i]]+1
}
plot(som.sc, type="grid",names=kounts)

As far I read in google, with the par(mfrow=c(1,2)) line should be fine, but it doesn't work. I ran the code and the first plot used the first half of the window, as it should be. But, the second plot use the entire window. Please, help me!. Thanks.

P.S.: The review of this post didn't allow me to write the entire code. I'm using the SOMbrero package.


Solution

  • Heatmaps will probably not work with par(). Maybe these will help:

    R: arranging multiple plots together using gridExtra

    to display two heatmaps in same pdf side by side in R