Topic: CTFS Plot Maps

Topic Description:

Functions for maps of CTFS plot data. The file map.r has functions for tree distribution maps, including overlays of elevation contours. The file mapresponse.r has functions for creating color or contour maps of any numerical responses, based on the R functions image, contour, and filled.contour.



File: map/map.r

View File Source Download File No help file available

Function: map

Function Description: map

Function to draw map of one or more species from one plot. Must give the complete plot dataset, in split format (list of one dataframe per species), and one or more species code. Other arguments are optional, however, many defaults can be adjusted to get a good map on the screen or exported. This calls the functions maptopo() and map1species() for the actual mapping.

A common problem is graph size, leading to an error message "Plot region too large". This happens if the export="no" option is used with the option plotside too large for the default graph size (usually 7 inches). If you use the option export="Windows", "Mac", or "Unix", then height and width can be set with arguments ht, wd, and plotside can be as large as you please.

Function Arguments:

ArgumentDefault Value
splitdatafile
species
spplistNULL
plotdimc(1000,500)
xrangec(0,plotdim[1])
yrangec(0,plotdim[2])
elevdataNULL
cutoffc(10,100,300,3000)
sizeNULL
deadtreeFALSE
maintitle''
titleposc(plotdim[1]/2,1.32*plotdim[2])
clrsNULL
bwFALSE
bgcolor'white'
symbolsNULL
xaxisTRUE
yaxisTRUE
addlegendTRUE
legposc(plotdim[1]/2,1.16*plotdim[2])
legsize0.75
labsize1.15
axisdiv100
bty'n'
ht6
wd9
plotside6
axspos0.5
topoclr'gray80'
topoint0
export'no'
filepath''
outfileNULL

Arguments Description:

  • splitdatafile: A full plot dataset in list format.
  • species: One or more species codes to be mapped.
  • spplist: A table with species codes and Latin names can be submitted as well, so that the full genus-species is added to plot. This must have species codes as row names. It should be the CTFS R format species table (eg, bci.spptable).
  • It can be set to NULL if not available, then only the species code (as submitted) appears on the map.
  • xrange and yrange: Minimum and maximum x coordinates and y coordinates to map. Allows a portion of plot to be drawn. Defaults to the entire plot.
  • plotdim: The x and y dimensions of the plot. This is used often in R package. Note it assumes the starting coordinates are zero. If they are not, then xrange and yrange must be used.
  • elevdata: Elevation data can be submitted, then a topo map is overlaid. Elevation data must be submitted as a matrix (as described in readelevdata in utilities.r).
  • cutoff: Diameter breaks for changing size of plotting points.
  • size: The size of plotting points, to match the number of diameter breaks. If NULL, a default set is assigned. This can require fiddling, as big points do not work for really abundant species, and small points for rare species.
  • deadtree: Set NULL to map all trees, alive and dead; TRUE for dead only, FALSE for live only (relies on status in the R table).
  • maintitle: A title to appear at the top of the page, above the species name.
  • titlepos: The position to place the title. The default is above the center of the plot, higher than the species name. It may require some fiddling on different screens to get it the right distance above.
  • clrs: A vector of color names, one for each species. If set to NULL, default values are assigned. See bw.
  • bw: If TRUE, only black, white, and grays are used.
  • bgcolor: The background color. Defaults to white. For presentation exports, try bgcolor="transparent".
  • symbols: A vector of symbols, one per species. Can be anything accepted by R for pch (plot character in the function plot()). If NULL, defaults are assigned.
  • addlegend, legpos, legsize: For the species name, whether to include, where to place, and font size. Try the defaults first before fiddling, or just set addlegend=FALSE to remove.
  • ht, wd, plotside: These are the height and width of the overall graph, and the vertical dimension (inches) of the map. The default work for pdf export or mapping to the screen, and ht and wd are inches. But if export is png, jpg, emf, height and width are pixels and need to be 500-1000.
  • labsize: Size of axis labels.
  • bty: Type of box to appear around species name. The default, 'n', means no box; set to 'o' to see the box.
  • axspos: Distance between axis numbers and axis.
  • topoint: Interval for topolines, if elevdata are submitted.
  • topoclr: Color of topolines.
  • export: See function define.graphwindow.
  • filepath: The folder to which map will be exported.
  • outfile: The name of the file to export to.


Sample Usage:

If you have saved split formatted data:
CTFSplot(plot='bci',census=6,type='split')
If you have not saved:
CTFSplot(plot='bci',census=6)
bci.split6=split.data(censdata=bci.full6,splitcol='sp')
nospp=length(species)
map(splitdatafile=bci.split6,species='poular')
map(splitdatafile=bci.split6,species='poular',export='pdf',filepath='~/data/maps/',outfile='Poulsenia1995map',plotside=10,ht=8.5,wd=11)
map(splitdatafile=bci.split6,species=c('guatdu','poular'))


Function Source:


map=function(splitdatafile,species,spplist=NULL,plotdim=c(1000,500),xrange=c(0,plotdim[1]),yrange=c(
        0,plotdim[2]),elevdata=NULL,
cutoff=c(10,100,300,3000),size=NULL,deadtree=FALSE,maintitle='',titlepos=c(plotdim[1]/2
        ,1.32*plotdim[2]),clrs=NULL,
bw=FALSE,bgcolor='white',symbols=NULL,xaxis=TRUE,yaxis=TRUE,addlegend=TRUE,legpos=c(plo
        tdim[1]/2,1.16*plotdim[2]),legsize=0.75,
labsize=1.15,axisdiv=100,bty='n',ht=6,wd=9,plotside=6,axspos=0.5,topoclr='gray80',topoi
        nt=0, export='no',filepath='',outfile=NULL)
{
filename=get.filename(file=outfile,path=filepath,exp=export,species=species)
define.graphwindow(exp=export,h=ht,w=wd,file=filename)
if(export!="unix" & export!="no" & export!="mac" & export!="windows") on.exit(graphics.off())

col=latin=character()
symb=numeric()

if(!is.null(spplist)) latin=spplist[species,]$Latin
else latin=species

nogrp=length(cutoff)-1
if(is.null(size)) size=setsize(nogrp,dim(load.species(species[1],splitdatafile))[1])

if(is.null(clrs))
{
if(!bw) col=c("blue","red","black","green","yellow","lightblue","orange")
else col=c("black","black","gray80","gray80","gray30","gray30")
}
else col=clrs

if(is.null(symbols))
{
if(bw) symb=rep(16,6)
else symb=c(16,1,16,1,16,1)
}
else symb=symbols

topo=FALSE
if(!is.null(elevdata)) topo=TRUE

if(topo)

maptopo(elev=elevdata,plotdim=plotdim,xaxis=xaxis,yaxis=yaxis,interval=topoint,ht=ht,wd=wd,plotsid
        e=plotside,labelsize=labsize, axspos=axspos,bgcolor=bgcolor,clr=topoclr)
# browser()
for(i in 1:length(species))
{
if(species[i] %in% names(splitdatafile)) sppdata=load.species(species[i],splitdatafile)
else sppdata=data.frame(gx=numeric(),gy=numeric(),dbh=numeric(),status=character())

if(is.null(deadtree)) sppdata=subset(sppdata,gx>=0 & gy>=0 & gx
else if(deadtree) sppdata=subset(sppdata,gx>=0 & gy>=0 & gx        'D') else sppdata=subset(sppdata,gx>=0 & gy>=0 & gx
if(i==1 & !topo)

map1species(sppdata,color=col[i],symbol=symb[i],size=size,xrange=xrange,yrange=yrange,xaxis=xax
        is,yaxis=yaxis,
cutoff=cutoff,plotdim=plotdim,plotside=plotside,bgcolor=bgcolor,axspos=axspos,labsi
        ze=labsize,axisdiv=axisdiv) else
map1species(sppdata,color=col[i],symbol=symb[i],cutoff=cutoff,xrange=xrange,yrange=yrange,
size=size,plotdim=plotdim,plotside=plotside,add=TRUE)
}

# browser()
oldpar=par(xpd=TRUE,font=3,xpd=NA)

text(x=titlepos[1],y=titlepos[2],labels=maintitle,col=col[1],font=2,cex=1.25)


if(addlegend) legend(x=legpos[1],y=legpos[2],legend=latin,xjust=0.5,col=col,text.col='black',bty=bt
        y,pch=16,horiz=T,y.intersp=1.2,cex=legsize) par(oldpar)

return(filename)
}