Kohonen Package
This turns out to be easy. What you need are the locations where to put the labels and those are given in the som object. Using your code: mysom <- som(wines.sc, grid=somgrid(5, 5, "hexagonal")) plot(mysom, type="dist.neighbours" ) # check what's contained in mysom: str(mysom) # we need the $grid$pts matrix of (x,y)-locations: text(mysom$grid$pts, labels=letters) # Your labels are too long to fit easily, # so abbreviate: mylabels <- abbreviate(colnames(wines), minlength=3) plot(mysom, type="dist.neighbours" ) text(mysom$grid$pts, labels=mylabels) -Peter Ehlers
Brock Tibert wrote:
Many thanks, Peter, Gavin. That is exactly what it was...and old version. I was running R 2.7 (needed it to integrate with SPSS 17). I know I am a pain, but one last question. Is it possible to overlay a value label onto the maps? In some of the SOMs we have worked through in class, we saw examples that overlay the observation's label onto the map so we could see where each observation fell. Again, many, many, many thanks. In just working through this one example, I have learned a ton about R. - Brock --- On Sun, 11/29/09, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
From: Gavin Simpson <gavin.simpson at ucl.ac.uk> Subject: Re: [R] Kohonen Package To: "Peter Ehlers" <ehlers at ucalgarywas.ca> Cc: "Brock Tibert" <btibert3 at yahoo.com>, r-help at r-project.org Date: Sunday, November 29, 2009, 6:21 AM On Sat, 2009-11-28 at 17:16 -0700, Peter Ehlers wrote:
I haven't used pkg:kohonen, so this is just guessing: 1. are you using an old version of the package?
I deleted the original email, so I'll reply here instead. The example provided by the OP works for me with on R 2.10-patched and:
packageDescription("kohonen")$Version
[1] "2.0.5" Looking at the CHANGES file in the package, "dist.neighbours" was added in version 2.0.5, so I suspect the OP was using an older version, but reading a newer version of the help as a PDF.
2. don't call the output of function som() 'som'. As people around here might say: would you call your iguana 'iguana'?
Indeed:
##install.packages("fortunes") ## uncomment if not
installed
require("fortunes")
fortune("dog")
HTH
G
3. have you used str() on your object to check what it really contains? I would guess that it should be of class som and have a component 'distances'. If none of that helps then it's beyond me. -Peter Ehlers Brock Tibert wrote:
Hi All, I am still learning R, but making, IMO, great
strides. I learned about Kohonen/Self-Organizing Maps in class and I would like to try to replicate some of the things we have seen in class.
Below is my code. I am trying to create a
u-matrix. In the documentation on page 9 it appears the type of plot, dist.neighbours should do the trick, however, I am getting an error:
(Error in match.arg(type) : 'arg' should be one
of "codes", "changes", "counts", "mapping", "property", "quality")
Since I am new to R, I figure I am missing
something obvious. Any help you can provide will be greatly appreciated!
Thanks in advance,
Brock
library(kohonen)
data("wines")
wines.sc <- scale(wines)
som <- som(wines.sc, grid=somgrid(5, 5,
"hexagonal"))
plot(som) plot(som, type="dist.neighbours" )
______________________________________________ R-help at r-project.org
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
reproducible code.
______________________________________________ R-help at r-project.org
mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained,
reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%