
Charlotte T. answered 05/01/20
MS in Geology and GIS with 6+ years of teaching experience
When Earth (and the rest of the solar system) was forming, small atoms of "star stuff" slowly collided and built up larger chunks, which then formed a molten ball of material that we call proto-Earth. Under the force of gravity, this ball of molten material was sorted by density as it spun and orbited the young Sun. Heavier atoms and molecules sunk to the core and lighter elements rose to the surface (the molten material was still mixed enough that heavy materials like iron and nickel exist on the surface). Because the Earth's interior has been sorting itself out for so long, the random scatter of atoms from Earth's formation has been organized into the (still complicated) layers of Earth we have today.
All minerals are based on the composition of the magma from which they form. If a mineral has silicon in it, it came from a silicon-rich magma. (A general example of this is mafic magmas forming basaltic rocks and felsic magmas forming granitic rocks. Mafic and felsic descriptors are based on the chemical composition of the material.) Rare minerals precipitate from magma that might have a more rare mix of chemical components. The volumes and concentrations of these large, rare-Earth mineral deposits varies based on the available atoms in a given mix of magma, which ranges in chemical diversity throughout the planet.