Janzen-Connell and tree diversity

ecology tutorial
R
community ecology
biodiversity
coexistence
The Janzen-Connell hypothesis in R: how specialised natural enemies near parent trees give rare species an edge and turn competitive exclusion into coexistence.
Author

Tidy Ecology

Published

2026-08-01

A hectare of tropical forest can hold several hundred tree species, and this is a genuine puzzle. Simple competition theory says the best competitor should win, and a species that is even slightly superior should, given time, take over. So why do so many species persist side by side, none of them running away with the forest? Janzen 1970 The American Naturalist 104(940):501-528 and Connell 1971 gave the same answer independently: the enemies of a tree do the work that competition cannot.

Enemies that punish being common

The Janzen-Connell hypothesis is about specialised natural enemies, the seed predators, insect herbivores and soil pathogens that attack one tree species and not others. These enemies build up wherever their host is abundant, in the soil beneath a parent tree and in patches where the species is locally common. A seed or seedling landing among many of its own kind is landing in a reservoir of its own specialised enemies, and it dies at a higher rate. The result is that a species suffers most exactly where it is most common, which caps every species before it can dominate and leaves room for the rest (Connell JH 1971, in den Boer and Gradwell, Dynamics of Populations: 298-312).

Model a whole community this way. Give each species a per-capita recruitment that falls as its own local frequency rises, the community-level footprint of its specialised enemies, and let the community iterate.

simcomm <- function(cndd, S = 8, T = 400, seed = 415) {
  set.seed(seed); f <- rep(1/S, S); fit <- runif(S, 0.9, 1.1)   # small fitness differences
  for (t in 1:T) {
    w <- fit * f * exp(-cndd * f)          # enemies cut recruitment where a species is common
    f <- w / sum(w)
  }
  f
}
round(rbind(no_enemies = simcomm(0), with_enemies = simcomm(6)), 3)
              [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]
no_enemies   0.000 0.000 0.000 0.000 1.000 0.000 0.000 0.000
with_enemies 0.124 0.128 0.113 0.123 0.139 0.117 0.124 0.133

Diversity from being punished

Without the density-dependent penalty, the community collapses to a single species: the one with the highest intrinsic fitness slowly excludes every other, and diversity falls to nothing. Turn the enemies on and all 8 species persist, at nearly even abundances.

shannon <- function(f) { f <- f[f > 0]; -sum(f * log(f)) }
c(species_no_enemies = sum(simcomm(0) > 0.005), shannon_no_enemies = shannon(simcomm(0)),
  species_with_enemies = sum(simcomm(6) > 0.005), shannon_with_enemies = shannon(simcomm(6)))
  species_no_enemies   shannon_no_enemies species_with_enemies 
        1.000000e+00         5.215997e-06         8.000000e+00 
shannon_with_enemies 
        2.077560e+00 

Without enemies, 1 species survives and Shannon diversity is 0.00. With them, 8 species coexist and diversity reaches 2.08, which is essentially the maximum possible for eight species, 2.08. The same small fitness differences that drove the forest to monoculture become harmless once every species is held back hardest when it gets ahead.

d <- rbind(data.frame(sp = factor(1:8), f = f_no,   rule = "no enemies"),
           data.frame(sp = factor(1:8), f = f_cndd, rule = "with specialised enemies"))
ggplot(d, aes(sp, f, fill = rule)) +
  geom_col(position = "dodge", width = 0.7) +
  scale_fill_manual(values = c("no enemies" = col_no, "with specialised enemies" = col_cndd)) +
  labs(x = "Species", y = "Relative abundance", fill = NULL,
       title = "Specialised enemies turn exclusion into coexistence")
Two sets of bars for eight species; without enemies one bar is at one and the rest at zero, with enemies all eight bars are roughly equal.
Figure 1: Species abundances after long competition. Without specialised enemies (ochre) the fittest species excludes the rest; with them (green) all eight coexist at even abundance.

From one hectare to a latitude gradient

Scale the argument up and it offers an explanation for one of the oldest patterns in ecology, the increase in species richness toward the equator. If specialised enemies are more effective in warm, wet, aseasonal tropics, where pests and pathogens are never knocked back by frost or drought, then density-dependent mortality should be stronger there, and stronger density dependence supports more species. Analyses of long-term forest plots have found exactly this signature (HilleRisLambers et al. 2002 Nature 417(6890):732-735). The relationship is smooth: stronger density dependence supports steadily more diversity, up to the even community the mechanism can sustain.

cg <- data.frame(cndd = seq(0, 10, 0.25))
cg$H <- sapply(cg$cndd, function(c) shannon(simcomm(c)))
ggplot(cg, aes(cndd, H)) +
  geom_hline(yintercept = Hmax, colour = col_ref, linetype = "dotted") +
  geom_line(colour = col_cndd, linewidth = 1) +
  annotate("text", x = 0.2, y = Hmax - 0.12, label = "maximum for the species pool", hjust = 0, colour = col_ref, size = 3.4) +
  labs(x = "Strength of enemy density dependence", y = "Shannon diversity",
       title = "Stronger density dependence, more coexisting species")
A rising curve of Shannon diversity against density-dependence strength, from near zero to a plateau at the maximum diversity for eight species.
Figure 2: Community diversity against the strength of specialised-enemy density dependence. At zero it collapses to one species; as density dependence strengthens, more species coexist, toward the maximum for the pool.

The mechanism behind all of it is a species doing worse where it is common, which the next post measures directly, and its coexistence logic is negative frequency dependence, the subject of the third post. Detecting it in real forests is deceptively hard, which is the checking post.

References

  • Connell JH 1971. In: den Boer PJ, Gradwell GR (eds) Dynamics of Populations. PUDOC, Wageningen: 298-312.
  • HilleRisLambers J et al. 2002. Nature 417(6890):732-735 (10.1038/nature00809).
  • Janzen DH 1970. The American Naturalist 104(940):501-528 (10.1086/282687).

Newsletter

Get new tutorials by email

New R and QGIS tutorials for ecologists, straight to your inbox. No spam; unsubscribe anytime.

By subscribing you agree to receive these emails and confirm your address once. See the privacy policy.