Changing axes in R with NMDS graphics

I am trying to change the axes in my NMDS plot to zoom in on my sites. I am assuming the space selected in the point product of the view that I have not plotted. I've tried adding xlim to my code to no avail and was wondering if I have it in the wrong place or if another action is required. Below is a copy of my code.

#NMDS on pooled abundance with NA omitted
NMDS_HPA<-metaMDS(HP_Abundance_omit[,-1],k=2, trymax=1000)
plot(NMDS_HPA, type="n", display="sites", xlim=c(-1.5,1.5))
with(descriptors, levels(T)) 
colorvec<-c("seagreen4", "tan4", "mediumblue")
plot(NMDS_HPA, type="n", xlim=c(-1.5,1.5))
title(main="NMDS using Abundance with Bray-Curtis", sub="Habitats Pooled")
ordihull(NMDS_HPA, groups=treat, draw="polygon", col="grey90", label=F)
with(descriptors, points(NMDS_HPA, display="sites", col=colorvec[T], pch=21, bg=colorvec[T]))
with(descriptors, legend("topright", legend=levels(T), bty="n", col=colorvec, pch=21, pt.bg=colorvec))

      

thank

+3


source to share


2 answers


If you don't set ylim

it either, then vegan has no choice but to show more (or less) the x-axis than you want, since the scaling of the axis must be preserved; a change in unit along one axis must coincide with the same change in unit along the other. Otherwise, how would you know how to represent Euclidean distances (easily) on a figure? Since these Euclidean distances are assumed to reflect the rank ordering of the original differences, it is important to maintain the aspect ratio or relative scaling of the axes to each other.

You can see this in action simply by using the mouse to zoom the device window onto the screen. R replaces the shape all the time using different axes to maintain an aspect ratio of 1.

Consider this reproducible example:

library("vegan")
data(dune)

set.seed(56)
sol <- metaMDS(dune)

      

Section selection in x and y axes works as expected

## zoom in on the section (-0.5,0.5)(-0.5,0.5)
plot(sol, xlim = c(-0.5, 0.5), ylim = c(-0.5,0.5))

      



enter image description here

If you want to keep the entire y-axis, but only show that the average is 50% of the x-axis, then you have to plot on a device whose width

value is ~ 50% of the value height

(roughly because R by default is to use different sized margins in the top / bottom left / right edges.)

png("~/mds-zoom2.png", height = 700, width = 350, res = 100, pointsize = 16)
plot(sol, xlim = c(-0.5, 0.5))
dev.off()

      

which produces

enter image description here

This is almost correct. You could solve the problem exactly by setting equal margins around the graph with par(mar = rep(4, 4) + 0.1)

and then work out the ratio of the range of points along the x and y axes (get scores(sol)

and calculate range()

on both columns then calculate the ratio of the two ranges) then use that to give you the desired height of the graph for the width you want to specify.

+1


source


If you just plotted points and not an NMDS object than xlim works just fine



plot(NMDS_HPA$points, xlim=c(-1.5,1.5))

      

0


source







All Articles