The concept of the "four temperaments" is derived from the now discredited pseudoscience of the "four humors" from Ancient Greek medicine. According to that theory, all illnesses were caused when a "normal" balance of humors — phlegm, blood, bile and black bile — was disrupted. The four temperaments were supposed to be caused by an excess of bile (choleric), blood (sanguine), phlegm (phlegmatic) and black bile (melancholic). The general idea is used for personality profiling even today.
But how did some ancient supposed healer come up with this theory in the first place?
Interestingly, observing a sample of blood provides an answer. Let a vial of human blood stand for a while and you will see it separate into four layers. Those layers comprise the four components of blood — plasma, haemoglobin, antibodies and platelets. Plasma is the liquid solvent that holds all the other parts of blood in it, and is clear in color. Haemoglobin aka the red blood cells are responsible for transporting oxygen to every part of the body, and is therefore red. Platelets are the clotting agent, that forms a coarse black outer layer, which restricts blood flow whenever it is exposed to air. Antibodies or white blood cells are responsible for fighting infections, and appear yellow in color. Someone could easily mistake plasma for phlegm, haemoglobin for blood, antibodies for yellow bile, and the platelet clot layer could have been designated as "black bile" for lack of a better term. More interestingly, these four components of blood could take on the characteristics of a Four-Temperament Ensemble themselves — plasma being the unassuming, cold to the touch Phlegmatic glue that binds the team together, haemoglobin being the high energy Sanguine that livens everything else up, antibodies being the hot tempered, bellicose Cholerics that accomplish important goals, but burning everything in the process, and platelets normally staying out of everyone's way, but bringing structure when most needed — and causing a lot of trouble for everything else by imposing their structure at the wrong place and time — just as a Melancholic would.
In actuality it is a different set of hormones that could cause these four temperaments — the Choleric is usually associated with testosterone and/or adrenaline, the Sanguine indicating an excess of dopamine, which influences pleasure seeking, the Phlegmatic being associated with oxytocin, which causes feelings of love and attraction, and the Melancholic being associated with serotonin, that causes sleepiness. Our bodies contain all of these hormones and uses them situationally.
In a similar manner, although someone may designate you as belonging to one of these temperaments, for whatever reason, that isn't a license to buy into the stereotype and continually act like it. Different situations may require different responses, and therefore one has to figure out when it is necessary to be Choleric and when to be Phlegmatic. (The series finale of The Shield, for example, had choleric Vic in a situation that required him to be melancholic.) On the other hand, (1) everyone is prone to an occasional impulse that goes against the situation, and (2) a writer may also apply the designation to one character in simple relation to the other three. Thus, a character can easily be in two different ensembles at once, such as the Phlegmatic in one and the Sanguine in the other.