jmbm

Fig_07

Oct 10th, 2022 (edited)
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.04 KB | None | 0 0
  1. pdf("fig_07.pdf", width = 5, height = 5)
  2. par(bty = "n", las = 1, mar = c(6, 4, 1, 1) + 0.2)
  3.  
  4. # función suma armónicos
  5. sum_arm <- function(n) {
  6.   a <- numeric(n)
  7.   for (i in 1:n) {
  8.     for (j in 1:i) {
  9.       a[j] <- a[j] + 1/i
  10.     }
  11.   }
  12.   a/n
  13. }
  14.  
  15. # datos
  16. obs <- c(26.5, 13.3, 8.7, 8.0, 7.8, 6.9, 5.5, 4.4, 4.0, 3.7, 3.4, 2.1, 2.1, 2.0, 1.6)
  17. nomb <- c("Sparisoma", "Diplodus", "otras", "Boops", "Sphyraena", "Sarpa", "Oblada", "Trachinotus", "Belone", "Muraena", "Cephalpods", "Mugilidae", "Pagellus", "Pagrus", "Pomadasys")
  18. n <- length(obs)
  19. teor <- 100*sum_arm(n)
  20.  
  21. R2 <- 1 - sum((obs - teor)^2) / var(obs) / (n - 1)
  22.  
  23. # gráfico
  24. plot(1:n - 0.1, obs, ylab = "Abundancia (%)", type = "h", las = 2, ylim = c(0, 30), lwd = 2, xlab = "", xaxt = "n")
  25. axis(1, at = 1:n, labels = nomb, las = 2, cex.axis = 0.8)
  26. lines(1:n + 0.1, teor, type = "h", col = "red", lwd = 2)
  27. legend("topright", bty = "n", cex = 0.8, c("observado", "teórico"), lty = 1, lwd = 2, col = c("black", "red"))
  28. text(10, 10, bquote(R^2 ~ ":" ~ .(round(R2, 2))))
  29.  
  30. dev.off()
Advertisement
Add Comment
Please, Sign In to add comment