[R] Vegan: how to plot sites labes in diversity plot

David Winsemius dwinsemius at comcast.net
Thu Nov 24 16:48:54 CET 2011


On Nov 24, 2011, at 8:12 AM, Alejo C.S. wrote:

> Dear List,
>
> I can'f figure how to add point labels in the next plot (example from
> ?taxondive help page, from vegan package):
>
> library(vegan)
> data(dune)
> data(dune.taxon)
> taxdis <- taxa2dist(dune.taxon, varstep=TRUE)
> mod <- taxondive(dune, taxdis)
> plot(mod)
>
> The points in this plot are diversity values of single sites, and I'd
> like to add a label to each one. The plot command don't accept a
> "label" argument.

Right. Generally you cannot just make up argument names and expect  
plotting routines to honor them. There is no "labels" argument in  
`plot.default` either.

class(mod)   # to figure out what vegan thinks it object is named
[1] "taxondive"
 > methods(plot)  # to make sure there is a specific plot method
 > vegan:::plot.taxondive  # triple dots because it is hidden
function (x, ...)
{
     plot(x$Species, x$Dplus, xlab = "Number of Species", ylab =  
expression(Delta^"+"),
         ...)
     i <- order(x$Species)
     abline(h = x$EDplus, ...)
     lines(x$Species[i], x$EDplus - 2 * x$sd.Dplus[i], ...)
     lines(x$Species[i], x$EDplus + 2 * x$sd.Dplus[i], ...)
}
<environment: namespace:vegan>

So from that above you see that the plotting routine is doing nothing  
special. Just plotting x,y values and a bit of annotation

So to plot "labels" offset a bit to the left and down you look at the  
scale of the plot dimension and take a guess at what will collide th  
least. There are also tricky routines in packages plotrix and Hmisc  
that will do the placement for you, but you clearly need to start  
learning basic R first.

  with( mod, text(Species-.3, Dplus-1, as.character(1:length(Dplus)))  )

-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list