[Ipmpack-users] plot legend (or not) with survModelComp

Eelke Jongejans e.jongejans at science.ru.nl
Wed Apr 3 17:54:36 CEST 2013


Dear Maria Paula,

you are right that it is not yet possible to indicate whether a legend 
needs to be plotted when running survModelComp and growthModelComp. This 
functionality will be included in the next version of IPMpack. If you 
can't wait: I've copied the new functions at the bottom of this email.

best wishes,
Eelke

>
> ----- Mensaje reenviado -----

> Dear IPMpack team,
> First at all it is a fantastic pack, congratulations.
> Using the IPMpack, I found two errors:
> 1.When I want to graph the */Survival and Growth models/* using 
> survModelComp and growthModelComp, I chose *legendPos = FALS, but I 
> still get the legend in the corner: see figures*
> resultsurv <- survModelComp(dataf = Sp, expVars = c(surv~1, surv~size, 
> surv~size +size2,
> surv~size +size2+size3),
> testType= "AIC",  makePlot = TRUE, *legendPos = FALSE*,
> ncuts= 100, mainTitle = "Survival")
>
> 2.     ....
> Thank for your help.
> Maria Paula



growthModelComp <- function(dataf,
         expVars = c(sizeNext~1, sizeNext~size, sizeNext~size + size2),
         regressionType = "constantVar",
         testType = "AIC",
         makePlot = FALSE,
         mainTitle = "",
         plotLegend = TRUE,
         legendPos = "topright", ...) {
     varN <- length(expVars)
     typeN <- length(regressionType)
     treatN <- varN * typeN
     summaryTable <- data.frame()
     grObj <- vector("list", length = treatN)
     i <- 1
     for(v in 1:varN) {
         for(t in 1:typeN) {
             grObj[[i]] <- makeGrowthObj(dataf = dataf, regType = 
regressionType[t], Formula = expVars[[v]])
             if 
(length(grep("decline",tolower(as.character(class(grObj[[i]])))))>0) {
                 summaryTable <- rbind(summaryTable, 
cbind(as.character(unlist(expVars))[v], regressionType[t], 
match.fun(testType)(grObj[[i]]@fit$fit)))
             } else {
             summaryTable <- rbind(summaryTable, 
cbind(as.character(unlist(expVars))[v], regressionType[t], 
match.fun(testType)(grObj[[i]]@fit)))
             }
             i <- i + 1
         }
     }
     summaryTable <- as.data.frame(summaryTable)
     names(summaryTable) <- c("Exp. Vars", "Reg. Type", testType)
     outputList <- list(summaryTable = summaryTable, growthObjects = grObj)

     # PLOT SECTION #
     if(makePlot == TRUE) {
         plotGrowthModelComp(grObj = grObj, summaryTable = summaryTable, 
dataf = dataf, expVars = expVars,  testType = "AIC", plotLegend = 
plotLegend, mainTitle = mainTitle, legendPos, ...)
     }
     return(outputList)
}


survModelComp <- function(dataf,
         expVars = c(surv~1, surv~size, surv~size + size2),
         testType = "AIC",
         makePlot = FALSE,
         mainTitle = "", ncuts = 20,
         plotLegend = TRUE,
         legendPos = "bottomleft", ...) {
     varN <- length(expVars)
     treatN <- varN
     summaryTable <- data.frame()
     svObj <- vector("list", length = treatN)
     i <- 1
     for(v in 1:varN) {
         svObj[[i]] <- makeSurvObj(dataf = dataf, Formula = expVars[[v]])
         summaryTable <- rbind(summaryTable, 
cbind(as.character(unlist(expVars))[v], 
match.fun(testType)(svObj[[i]]@fit)))
         i <- i + 1
     }
     summaryTable <- as.data.frame(summaryTable)
     names(summaryTable) <- c("Exp. Vars", testType)
     outputList <- list(summaryTable = summaryTable, survObjects = svObj)

     # PLOT SECTION #
     if(makePlot == TRUE) {
         ## this is the surv picture
         plotSurvModelComp(svObj = svObj, summaryTable = summaryTable, 
dataf = dataf, expVars = expVars, testType = "AIC", plotLegend = 
plotLegend, mainTitle = mainTitle, ncuts = ncuts, legendPos = legendPos, 
...)
     }
     return(outputList)
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/ipmpack-users/attachments/20130403/595c0670/attachment.html>


More information about the IPMpack-users mailing list