Dr. Stevens, Hi, my name is Trey Scott, and I'm a grad student of Brian McCarthy's. He referred me to you because of your expertise in handling complex R problems. We were hoping you could help us solve a nagging problem that is prohibiting me from producing graphicl output. Here is a simple mock-up of the matrix I'm using a b c d e f 1i 1 4 7 9 2 5 2i 12 17 6 2 3 7 3i 2 5 8 1 3 2 1c 0 2 4 7 2 1 2c 0 1 4 6 9 10 3c 13 15 19 10 8 9 Where: 1i-3i are "infested" sites, and 1c-3c are "control sites". A-F are species found at each site. I have several of these ordinations to perform on different variables (BA, density, RIV, cover, etc..., all in different matrices). I'm running NMDS (metaMDS) ordinations on each matrices, and producing ordination graphs for each cloud of points. The problem I have is that I cannot devise a way to split the cloud of points into infested and control so that I can deduce any significant groupings. A simple difference in symbols/color (Ex. gray triangles for infested, black circles for control) would do. Also, I understand the use of pch/col/cex, I just need to apply them to the "split". So: + How would I split these out in R after I run the metaMDS in vegan? + What code would be necessary to bring this about? McCarthy and I are at the end of our preoverbial rope on this; nothing has worked. -- View this message in context: http://n4.nabble.com/NMDS-Ordination-Graphics-Problem-tp1751845p1751845.html Sent from the R help mailing list archive at Nabble.com.
This is the easiest way I have found to do something similar to what you want. #output of dput() easy way to share data with the list x <- (structure(list(a = c(1L, 12L, 2L, 0L, 0L, 13L), b = c(4L, 17L, 5L, 2L, 1L, 15L), c = c(7L, 6L, 8L, 4L, 4L, 19L), d = c(9L, 2L, 1L, 7L, 6L, 10L), e = c(2L, 3L, 3L, 2L, 9L, 8L), f = c(5L, 7L, 2L, 1L, 10L, 9L)), .Names = c("a", "b", "c", "d", "e", "f"), class "data.frame", row.names = c("1i", "2i", "3i", "1c", "2c", "3c"))) library(vegan) library(ggplot2) p <- metaMDS(x) y <- do.call(rbind,strsplit(as.character(rownames(x)), split="")) z <- data.frame(sample = y[,1], status = y[,2], p$points[,1:2]) qplot(X1,X2, data=z, shape=status) On Mon, Apr 5, 2010 at 12:58 PM, Trey <trey3_79 at hotmail.com> wrote:> > Dr. Stevens, > > Hi, my name is Trey Scott, and I'm a grad student of Brian McCarthy's. ?He > referred me to you because of your expertise in handling complex R problems. > We were hoping you could help us solve a nagging problem that is prohibiting > me from producing graphicl output. > > Here is a simple mock-up of the matrix I'm using > > ? ? ? ?a ? ? b ? ? c ? ? d ? ? e ? ? f > 1i ? ? ?1 ? ? 4 ? ? 7 ? ? 9 ? ? 2 ? ? 5 > 2i ? ? ?12 ? 17 ? ?6 ? ? 2 ? ? 3 ? ? 7 > 3i ? ? ? 2 ? ?5 ? ? 8 ? ? 1 ? ? 3 ? ? 2 > 1c ? ? ?0 ? ?2 ? ? 4 ? ? 7 ? ? 2 ? ? 1 > 2c ? ? ?0 ? ?1 ? ? 4 ? ? 6 ? ? 9 ? ? 10 > 3c ? ? ?13 ? 15 ? 19 ? 10 ? ?8 ? ? 9 > > Where: ?1i-3i are "infested" sites, and 1c-3c are "control sites". ?A-F are > species found at each site. ?I have several of these ordinations to perform > on different variables (BA, density, RIV, cover, etc..., all in different > matrices). ?I'm running NMDS (metaMDS) ordinations on each matrices, and > producing ordination graphs for each cloud of points. ?The problem I have is > that I cannot devise a way to split the cloud of points into infested and > control so that I can deduce any significant groupings. ?A simple difference > in symbols/color (Ex. gray triangles for infested, black circles for > control) would do. ?Also, I understand the use of pch/col/cex, I just need > to apply them to the "split". > > So: > > + ? How would I split these out in R after I run the metaMDS in vegan? > + ? What code would be necessary to bring this about? > > McCarthy and I are at the end of our preoverbial rope on this; nothing has > worked. > -- > View this message in context: http://n4.nabble.com/NMDS-Ordination-Graphics-Problem-tp1751845p1751845.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
hi, maybe you should see: http://cc.oulu.fi/~jarioksa/softhelp/FAQ-vegan.html#How-to-use-different-plotting-symbols-in-ordination-graphics_003f greetings, kay -- View this message in context: http://n4.nabble.com/NMDS-Ordination-Graphics-Problem-tp1751845p1752557.html Sent from the R help mailing list archive at Nabble.com.
Hi Trey, On Mon, Apr 5, 2010 at 1:58 PM, Trey <trey3_79 at hotmail.com> wrote:> > Dr. Stevens, > > Hi, my name is Trey Scott, and I'm a grad student of Brian McCarthy's. ?He > referred me to you because of your expertise in handling complex R problems. > We were hoping you could help us solve a nagging problem that is prohibiting > me from producing graphicl output. > > Here is a simple mock-up of the matrix I'm using > > ? ? ? ?a ? ? b ? ? c ? ? d ? ? e ? ? f > 1i ? ? ?1 ? ? 4 ? ? 7 ? ? 9 ? ? 2 ? ? 5 > 2i ? ? ?12 ? 17 ? ?6 ? ? 2 ? ? 3 ? ? 7 > 3i ? ? ? 2 ? ?5 ? ? 8 ? ? 1 ? ? 3 ? ? 2 > 1c ? ? ?0 ? ?2 ? ? 4 ? ? 7 ? ? 2 ? ? 1 > 2c ? ? ?0 ? ?1 ? ? 4 ? ? 6 ? ? 9 ? ? 10 > 3c ? ? ?13 ? 15 ? 19 ? 10 ? ?8 ? ? 9 > > Where: ?1i-3i are "infested" sites, and 1c-3c are "control sites". ?A-F are > species found at each site. ?I have several of these ordinations to perform > on different variables (BA, density, RIV, cover, etc..., all in different > matrices). ?I'm running NMDS (metaMDS) ordinations on each matrices, and > producing ordination graphs for each cloud of points. ?The problem I have is > that I cannot devise a way to split the cloud of points into infested and > control so that I can deduce any significant groupings. ?A simple difference > in symbols/color (Ex. gray triangles for infested, black circles for > control) would do. ?Also, I understand the use of pch/col/cex, I just need > to apply them to the "split". > > So: > > + ? How would I split these out in R after I run the metaMDS in vegan? > + ? What code would be necessary to bring this about? > > McCarthy and I are at the end of our preoverbial rope on this; nothing has > worked. > --Was the solution I sent you the other day not helpful? http://n4.nabble.com/How-to-split-data-for-NMDS-plots-td1751101.html#a1751290 If not perhaps you can explain what went wrong. Also you can post a small example of your data using dput(). The best way that I have found to make ordination plots in vegan is to make them in pieces. Michael -- Michael Denslow I.W. Carpenter Jr. Herbarium [BOON] Department of Biology Appalachian State University Boone, North Carolina U.S.A. -- AND -- Communications Manager Southeast Regional Network of Expertise and Collections sernec.org 36.214177, -81.681480 +/- 3103 meters
On Mon, 2010-04-05 at 09:58 -0800, Trey wrote:> Dr. Stevens,Hmm, did you get the wrong address there ;-) As Michael Denslow has mentioned, the way to handle this sort of customised plotting at the moment in vegan is to build the plot up by hand. Michael's response earlier showed you how to do it with the in-built data set. Here's how I'd do it (essentially the same thing), using Stephen Sefick's conveniently dput()ed version of your example data: ## something to hold the data dat <- (structure(list(a = c(1L, 12L, 2L, 0L, 0L, 13L), b = c(4L, 17L, 5L, 2L, 1L, 15L), c = c(7L, 6L, 8L, 4L, 4L, 19L), d = c(9L, 2L, 1L, 7L, 6L, 10L), e = c(2L, 3L, 3L, 2L, 9L, 8L), f = c(5L, 7L, 2L, 1L, 10L, 9L)), .Names = c("a", "b", "c", "d", "e", "f"), class "data.frame", row.names = c("1i", "2i", "3i", "1c", "2c", "3c"))) ## to hold the factor for whether a site is infested or control tlabs <- c("infested","control") treat <- factor(rep(tlabs, each = 3), levels = tlabs) ## setting the levels explicitly insures R doesn't reorder them alphabetically ## sanity check: all.equal(length(treat), nrow(dat)) ## do the analysis p <- metaMDS(x) ## set-up the plotting region: plot(p, display = "sites", type = "n") ## now add the points, coding the infested/control by colour and pch ## this is where I differ slightly from the example Michael gave ## as here the user can specify the cols, pchs etc required cols <- c("red","navy") ## chose what you want pchs <- c(3,16) ## ditto choose what you want points(p, display = "sites", pch = pchs[treat], col = cols[treat]) ## add a legend: legend("topleft", legend = levels(treat), pch = pchs, col = cols, bty "n") Notice how I've done the indexing there. Remember treat is a factor with more than two observations in it. In the points call above we rely on the factor being coded internally as 1,2,3,...,k for the k levels in the factor. To see what is actually being passed to col in the above call, do: cols[treat] So we've only specified our two colours and then used the treatment variable created earlier to do the right thing for us. If you have more toruble with vegan, try posting on the R SIG Ecology list (as that's where Jari Oksanen tends to hang out rather than R-Help) or on the R-Forge forum for Vegan: http://r-forge.r-project.org/forum/forum.php?forum_id=194 HTH G> > Hi, my name is Trey Scott, and I'm a grad student of Brian McCarthy's. He > referred me to you because of your expertise in handling complex R problems. > We were hoping you could help us solve a nagging problem that is prohibiting > me from producing graphicl output. > > Here is a simple mock-up of the matrix I'm using > > a b c d e f > 1i 1 4 7 9 2 5 > 2i 12 17 6 2 3 7 > 3i 2 5 8 1 3 2 > 1c 0 2 4 7 2 1 > 2c 0 1 4 6 9 10 > 3c 13 15 19 10 8 9 > > Where: 1i-3i are "infested" sites, and 1c-3c are "control sites". A-F are > species found at each site. I have several of these ordinations to perform > on different variables (BA, density, RIV, cover, etc..., all in different > matrices). I'm running NMDS (metaMDS) ordinations on each matrices, and > producing ordination graphs for each cloud of points. The problem I have is > that I cannot devise a way to split the cloud of points into infested and > control so that I can deduce any significant groupings. A simple difference > in symbols/color (Ex. gray triangles for infested, black circles for > control) would do. Also, I understand the use of pch/col/cex, I just need > to apply them to the "split". > > So: > > + How would I split these out in R after I run the metaMDS in vegan? > + What code would be necessary to bring this about? > > McCarthy and I are at the end of our preoverbial rope on this; nothing has > worked.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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 %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%