/R/plot.decorana.R

http://github.com/jarioksa/vegan · R · 76 lines · 75 code · 0 blank · 1 comment · 47 complexity · 0ab3b62ac155ede193867f43640dbd34 MD5 · raw file

  1. "plot.decorana" <-
  2. function (x, choices = c(1, 2), origin = TRUE, display = c("both",
  3. "sites", "species", "none"), cex = 0.8, cols = c(1, 2), type, xlim, ylim,
  4. ...)
  5. {
  6. display <- match.arg(display)
  7. sites <- x$rproj
  8. specs <- x$cproj
  9. if (missing(type)) {
  10. nitlimit <- 120
  11. nit <- 0
  12. if (display == "sites" || display == "both")
  13. nit <- nit + nrow(sites)
  14. if (display == "species" || display == "both")
  15. nit <- nit + nrow(specs)
  16. if (nit > nitlimit)
  17. type <- "points"
  18. else type <- "text"
  19. }
  20. else type <- match.arg(type, c("text", "points", "none"))
  21. if (origin) {
  22. sites <- sweep(x$rproj, 2, x$origin, "-")
  23. specs <- sweep(x$cproj, 2, x$origin, "-")
  24. }
  25. sitnam <- rownames(x$rproj)
  26. spenam <- rownames(x$cproj)
  27. sites <- sites[, choices]
  28. specs <- specs[, choices]
  29. ## Use linestack if only one dim was specified (and exit)
  30. if (NCOL(sites) == 1 && NCOL(specs) == 1) {
  31. pl <- linestack(sites,
  32. ylim = range(c(sites, specs), na.rm = TRUE), ...)
  33. linestack(specs, side = "left", add = TRUE, ...)
  34. return(invisible(pl))
  35. }
  36. sp.x <- range(specs[, 1])
  37. sp.y <- range(specs[, 2])
  38. st.x <- range(sites[, 1])
  39. st.y <- range(sites[, 2])
  40. switch(display, both = {
  41. if (missing(xlim)) xlim <- range(sp.x, st.x)
  42. if (missing(ylim)) ylim <- range(sp.y, st.y)
  43. }, sites = {
  44. if (missing(xlim)) xlim <- st.x
  45. if (missing(ylim)) ylim <- st.y
  46. }, species = {
  47. if (missing(xlim)) xlim <- sp.x
  48. if (missing(ylim)) ylim <- sp.y
  49. }, none = {
  50. if (missing(xlim)) xlim <- range(sp.x, st.x)
  51. if (missing(ylim)) ylim <- range(sp.y, st.y)
  52. })
  53. plot(sites, type = "n", xlim = xlim, ylim = ylim, asp = 1,
  54. ...)
  55. if (origin) {
  56. abline(h = 0, lty = 3)
  57. abline(v = 0, lty = 3)
  58. }
  59. else {
  60. abline(h = x$origin[choices[2]], lty = 3)
  61. abline(v = x$origin[choices[1]], lty = 3)
  62. }
  63. if (type != "none" && (display == "both" || display == "sites")) {
  64. if (type == "text" && !is.null(sitnam))
  65. text(sites, sitnam, cex = cex, col = cols[1])
  66. else points(sites, cex = cex, col = cols[1])
  67. }
  68. if (type != "none" && (display == "both" || display == "species")) {
  69. if (type == "text" && !is.null(spenam))
  70. text(specs, spenam, cex = cex, col = cols[2])
  71. else points(specs, pch = "+", cex = cex, col = cols[2])
  72. }
  73. out <- list(sites = sites, species = specs)
  74. class(out) <- "ordiplot"
  75. invisible(out)
  76. }