Two core questions in plant community ecology are to what extent the distributions of species are structured by local environmental conditions, and whether taxa differ in this regard. We compared the distributions of trees, Melastomataceae and ferns on soil and topographic gradients in a Costa Rican lowland rain forest (trees and ferns 983 plots, Melastomataceae 277 plots). To test whether these plant groups differed in the prevalence or type of habitat specialization, we calculated species’ environmental optima and tolerances on each gradient. Habitat specialization was defined as a significantly biased optimum, or a narrow tolerance, relative to values obtained under spatially restricted randomizations of species occurrences. Within plant groups, we also asked whether the dispersion of species optima differed from random expectation on each gradient. Fern optima were over-dispersed on multiple gradients, implying considerable interspecific habitat partitioning, and tree optima were over-dispersed in relation to topographic position. Habitat specialization was more prevalent in the two predominantly understorey groups than in trees (75% of Melastomataceae species, 81–87% of ferns, 57–58% of trees). Species optima of Melastomataceae and ferns also tended towards lower landscape positions than did those of trees, perhaps reflecting a higher proportion of drought-sensitive species in these two groups.