Certain groups of minerals are found in various parts of the world whose crystals are similar in form to each other, but somewhat different in their other properties, such as color and hardness. Some minerals are widely different; other minerals appear to have properties that are intermediate between them.
When these minerals are compared with each other in the laboratory, some of these minerals are found to have exactly the same molecular structure, and nearly the same chemical makeup, but because one of the atoms in the structure can be substituted with a different atom, there is a continuous gradation between a minerals with all of one type of atom, minerals with all of another atom, and possibly other minerals with yet other atoms.
By far the most common is in igneous rocks (or during melting and recrystallization associated with metamorphism). The local conditions determined that a mineral of that general structure was going to be formed; the particular proportion between the two variable atoms in the magma at the time the rocks crystallized determined where in the group the mineral that crystallized out of the magma was going to appear.
The other mechanism occurs during metamorphism. Minerals at the two extremes are brought into close contact with each other; the substitutable atoms begin to diffuse through the solid rock into the regions of the other tpye of mineral. In this way, regions of varying amounts of the substituable atoms form in between the "purer" forms.
A good example is the olivine group, which contains the extremes of Forsterite (Mg2SiO4) and Fayalite (Fe2SiO4). All sorts of gradations between these two extremes exist.
A more complex example is that of the pyroxene group. Pyroxenes are chains of silica tetrahedra held together most commonly by Magnesium, Calcium, and Iron atoms. Pyroxenes are usually represented in a triangular diagram with a "pure" member at each corner. Any point inside the triangle represents a different pyroxene composition.