The natural world is replete with examples of evolutionary convergence. That’s when two organisms that didn’t get traits they have in common from the same ancestor but instead got them on their own, in response to separate environmental pressures.

Medicinal aloe (aloe vera), from sub-Saharan Africa (Voxitatis)

Thorn-crested agave (agave iophantha), from the Southwestern US (Voxitatis)
In the Desert Botanical Garden in Phoenix, there’s a special exhibit that addresses the evolutionary convergence of the agave genus of plants and the aloe genus. These two genuses aren’t even in the same family, and they came into being in ecosystems that are very far apart: The agaves, also known as century plants, exist in Mexico and the Desert Southwest. Aloes, by contrast, exist on the African continent south of the Sahara Desert.
The environment in southern Africa is similar to that in the Desert Southwest: hot, dry, desert-like. As you can see from the pictures, the thorn-crested agave has traits similar to those of the aloe vera plant: thorns, thick leaves that come to a point, and so on.
Also, both plants can produce a sugary nectar that has been reported to have medicinal qualities. This, of course, makes it more likely that animals such as hummingbirds will pollinate the plants. (The plants aren’t very fragrant, which doesn’t bother the hummingbirds, since they have no sense of smell. On the other hand, bees have trouble with both plants, because they rely on the sense of smell to find nectar.)
The thorns that each developed are clearly there to keep non-pollinator animals from eating the leaves. Not only do the thorns act as swords to injure any potential herbivores, but they also act, mainly through their coloration, to warn potential herbivores away, a 2011 study published in Plant Signaling & Behavior suggests.
Researcher Simcha Lev-Yadun of Haifa University in Israel reminds readers that “the above-ground parts of plants are commonly utilized as food by various types of visually oriented herbivores. Thus, there is a permanent evolutionary arms race between plants and their herbivores in which, on an evolutionary time scale, plants acquire better defenses and herbivores partly or fully overcome them. One of the proposed defense methods of toxic or spiny plants against herbivory is visual aposematism (warning coloration).”
Animals do this sort of thing all the time. Think about insects that have developed the yellow and brown stripes seen in dangerous wasps. Think about caterpillars that use coloration not only as camouflage but as a warning. Think about birds that have developed coloration patterns that make them look unpalatable to potential predators.
It’s known as aposematic coloration, but researchers have generally paid little attention to it in plants, Lev-Yadun writes. “Only recently has it been proposed that colorful spines and associated conspicuous coloration patterns are cases of vegetal aposematic coloration analogous to such coloration in poisonous or dangerous animals, and that spine colors or associated patterns of coloration communicate between plants and potential herbivores.”