[R-sig-eco] Plotting different symbols almost works

Philip Dixon pdixon at iastate.edu
Thu Jan 13 14:49:18 CET 2011


This sort of problem happens all the time.  Another general solution to 
this and other 'plot groups with different colours/symbols/ ...' is to 
let R tell you the factor names and use a loop to plot each group 
separately.  This works with any type of groups, not just factors with 
the factor codes from 1 to n.

# use a plot function with type='n' to setup the plot and draw axes

grps <- unique(pos$for_pos_anl)      # the levels of grp

allpch <- c(16,17,4)                            # order here corresponds 
to order in grps
allcol <- c('green','black','red')

# add each group to plot
for (i in 1:length(grps)) {
   points.metaMDS(ScoresNMDS[pos$for_pos_anl==grps[i],  
],display="sites",choices= c(1,3), cex=0.8,
     pch = allpch[i],  col=allcol[i])
   }

Best wishes,
Philip Dixon



More information about the R-sig-ecology mailing list