An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20130819/e1378a4e/attachment.pl>
point color in NMDS (vegan)
6 messages · Elaine Kuo, Baldwin, Jim -FS, Vít Syrovátka +1 more
I assume that the dataset "island" is yours so I've made that equivalent to an example dataset in vegan named "dune". Below is a rather brute force way to assign colors.
library(MASS)
library(vegan)
data(dune)
island = dune
island.NMDS <- metaMDS(island,k=2, distfun = betadiver,
distance = "sim", trymax=100, zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
col = rep("black",dim(island)[2])
c = colnames(island)
col[c=="Belper" | c=="Elepal" | c=="Viclat" | c=="Brarut"] = "blue"
col[c=="Airpra" | c=="Rumace" | c=="Potpal" | c=="Tripra"] = "red"
col[c=="Sagpro" | c=="Agrsto" | c=="Hyprad" | c=="Poapra"] = "green"
points(island.NMDS, display = 'species', pch = '+', cex = 0.6, col=col)
# sites as text
col = rep("black",dim(island)[1])
r = rownames(island)
col[r=="2" | r=="17" | r=="18"] = "blue"
col[r=="3" | r=="10" | r=="20"] = "red"
text(island.NMDS, display = 'sites',col=col)
Jim Baldwin
USDA Forest Service
-----Original Message-----
From: r-sig-ecology-bounces at r-project.org [mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Elaine Kuo
Sent: Sunday, August 18, 2013 4:02 PM
To: <r-sig-ecology at r-project.org>
Subject: [R-sig-eco] point color in NMDS (vegan)
Dear List,
This is Elaine.
I am using metaMDS in package vegan to plot NMDS.
However, I want to draw the points using different colors according to island sites.
For example:
island site 1: island B, C, D => blue
island site 2: island A, E, F => green
island site 3: island G, H, J => red
Please kindly advise how to modify the following code to classify the sites by colors.
Thank you
Elaine
library(MASS)
library(vegan)
island.NMDS <- metaMDS(island,k=2, distfun = betadiver, distance =
"sim",trymax=100,zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
points(island.NMDS, display = 'species', pch = '+', cex = 0.6)
# sites as text
text(island.NMDS, display = 'sites')
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately.
Hi Elaine,
Maybe an easier way is to create a factor that will assign the islands
into groups.
If you want to classify the islands manually, then it might be better
to use Excel or another tabular processor.
Following your example:
groups<- factor(c('site2', 'site1', 'site1', 'site1', 'site2', 'site2',
'site3', 'site3', 'site3'))
(supposing the islands are in alphabetical order)
And now one can use the factor as a subscript to pick the right colors:
points(island.NMDS, display = 'species', pch = '+', cex = 0.6, col=
c('blue','green','red')[groups])
Note that this is a rather basic procedure, which you can learn from
many documents related to R and easily accessible on the internet, e.g.
see http://cran.r-project.org/other-docs.html
Cheers,
Vit
Dne 2013-08-19 03:59, Baldwin, Jim -FS napsal:
I assume that the dataset "island" is yours so I've made that
equivalent to an example dataset in vegan named "dune". Below is a
rather brute force way to assign colors.
library(MASS)
library(vegan)
data(dune)
island = dune
island.NMDS <- metaMDS(island,k=2, distfun = betadiver,
distance = "sim", trymax=100, zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
col = rep("black",dim(island)[2])
c = colnames(island)
col[c=="Belper" | c=="Elepal" | c=="Viclat" | c=="Brarut"] = "blue"
col[c=="Airpra" | c=="Rumace" | c=="Potpal" | c=="Tripra"] = "red"
col[c=="Sagpro" | c=="Agrsto" | c=="Hyprad" | c=="Poapra"] = "green"
points(island.NMDS, display = 'species', pch = '+', cex = 0.6,
col=col)
# sites as text
col = rep("black",dim(island)[1])
r = rownames(island)
col[r=="2" | r=="17" | r=="18"] = "blue"
col[r=="3" | r=="10" | r=="20"] = "red"
text(island.NMDS, display = 'sites',col=col)
Jim Baldwin
USDA Forest Service
-----Original Message-----
From: r-sig-ecology-bounces at r-project.org
[mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Elaine Kuo
Sent: Sunday, August 18, 2013 4:02 PM
To: <r-sig-ecology at r-project.org>
Subject: [R-sig-eco] point color in NMDS (vegan)
Dear List,
This is Elaine.
I am using metaMDS in package vegan to plot NMDS.
However, I want to draw the points using different colors according
to island sites.
For example:
island site 1: island B, C, D => blue
island site 2: island A, E, F => green
island site 3: island G, H, J => red
Please kindly advise how to modify the following code to classify the
sites by colors.
Thank you
Elaine
library(MASS)
library(vegan)
island.NMDS <- metaMDS(island,k=2, distfun = betadiver,
distance =
"sim",trymax=100,zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
points(island.NMDS, display = 'species', pch = '+', cex = 0.6)
# sites as text
text(island.NMDS, display = 'sites')
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. _______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
I have some posts on my blog that explain how to do this, ain the vein of Vit's reply (indexing via a factor). This way is preferable to that of Jim's brute-force way, but might seem somewhat magical if you aren't familiar with indexing rules and how factors are handled. Anyway, here is the link to the blog post with working examples: http://www.fromthebottomoftheheap.net/2012/04/11/customising-vegans-ordination-plots/ Anjoy, G
On 18 August 2013 17:02, Elaine Kuo <elaine.kuo.tw at gmail.com> wrote:
Dear List,
This is Elaine.
I am using metaMDS in package vegan to plot NMDS.
However, I want to draw the points using different colors according to
island sites.
For example:
island site 1: island B, C, D => blue
island site 2: island A, E, F => green
island site 3: island G, H, J => red
Please kindly advise how to modify the following code to classify the sites
by colors.
Thank you
Elaine
library(MASS)
library(vegan)
island.NMDS <- metaMDS(island,k=2, distfun = betadiver, distance =
"sim",trymax=100,zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
points(island.NMDS, display = 'species', pch = '+', cex = 0.6)
# sites as text
text(island.NMDS, display = 'sites')
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Gavin Simpson, PhD
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-ecology/attachments/20130820/535626fe/attachment.pl>
Yes, look at ?dune.env for what it contains. G
On 19 August 2013 16:45, Elaine Kuo <elaine.kuo.tw at gmail.com> wrote:
Hello Gavin, Thanks for mentioning your blog. I would like what dune.env is, since it is very important to generate different colors. Is dune.env different from dune? What will the dune.env be in the case of metaMDS instead of rda? Thank you again Elaine On Tue, Aug 20, 2013 at 12:08 AM, Gavin Simpson <ucfagls at gmail.com> wrote:
I have some posts on my blog that explain how to do this, ain the vein of Vit's reply (indexing via a factor). This way is preferable to that of Jim's brute-force way, but might seem somewhat magical if you aren't familiar with indexing rules and how factors are handled. Anyway, here is the link to the blog post with working examples: http://www.fromthebottomoftheheap.net/2012/04/11/customising-vegans-ordination-plots/ Anjoy, G On 18 August 2013 17:02, Elaine Kuo <elaine.kuo.tw at gmail.com> wrote:
Dear List,
This is Elaine.
I am using metaMDS in package vegan to plot NMDS.
However, I want to draw the points using different colors according to
island sites.
For example:
island site 1: island B, C, D => blue
island site 2: island A, E, F => green
island site 3: island G, H, J => red
Please kindly advise how to modify the following code to classify the
sites
by colors.
Thank you
Elaine
library(MASS)
library(vegan)
island.NMDS <- metaMDS(island,k=2, distfun = betadiver, distance
=
"sim",trymax=100,zerodist="add")
plot(island.NMDS, type = "n")
# species as symbols
points(island.NMDS, display = 'species', pch = '+', cex = 0.6)
# sites as text
text(island.NMDS, display = 'sites')
[[alternative HTML version deleted]]
_______________________________________________ R-sig-ecology mailing list R-sig-ecology at r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
-- Gavin Simpson, PhD
Gavin Simpson, PhD