I heard the following from an episode of QI (Season F, episode "Fakes and Frauds"), plus have added a little research of my own.
In the mid-1800s, Emperor Napoleon III of France offered a prize for anyone who could come up with a suitable alternative for butter, especially if it was something convenient for the army to use. Hippolyte Mège-Mouriès built off the work of Michel Eugène Chevreul, and lo! margarine was born! Who knew that France was a hotbed of collaborative butter-product development?
It was slow to gain traction, but eventually made it to the States. There, the dairy states were HORRIFIED by this poor substitute and wanted to do whatever they could to keep people from buying it. Most dairy states had bans on coloring margarine yellow, because people might think it was actually a cheaper version of butter. They hoped that the white color would gross people out and remind them exactly what it was: spreadable fat.
New Hampshire had especially strict regulations and had their margarine colored bright red, so people would be freaked out when they spread it on anything.
I think they were working from nature–if a bug is brightly colored, it is to warn predators that it is poisonous to eat. Though the red color law was eventually repealed, this logic did not work with humans. Just last week I gleefully sprinkled some day-glo orange cheese powder on my boxed mac & cheese mix, and I have never been happier.