The term red rag denotes a piece of red cloth used to provoke an animal, especially a bull (in early use a fowl). Figuratively, especially in the phrase like a red rag to a bull, this term denotes a source of provocation or annoyance, something which excites violent indignation.
(However, with bulls, the stimulus appears to be the movement of the rag, as they are blind to the colour red.)
An early reference to the notion occurs in Euphues and his England, Containing his voyage and aduentures, myxed with sundrie pretie discourses of honest Loue, the discription of the countrey, the Court, and the manners of that Isle. […] (London: Printed for Gabriel Cawood, 1580), by the English author John Lyly (circa 1553-1606):
He that commeth before an Elephant will not weare bright coulours, nor he that cōmeth to a Bull, red, nor hée that standeth by a Tyger, play on a Taber: for yt by the sight or noise of these things, they are commonly much infensed [= incensed].
The British authors John Trenchard (1662-1723) and Thomas Gordon (circa 1691-1750) wrote the following in The Independent Whig: Or, a Defence of Primitive Christianity, and of our Ecclesiastical Establishment, against the Exorbitant Claims and Encroachments of Fanatical and Disaffected Clergymen (London, England) of Saturday 7th January 1721:
—from the fifth edition (London: Printed for John Peele, 1732):
Nature works by a thousand ways imperceptible to us: The Loadstone draws Iron to it, Gold, Quick- silver; the sensitive Plant shrinks from the Touch; some sorts of Vegetables attract one another and twine together; others grow farther apart; the treading upon the Torpedo affects, and gives raging Pains to our whole Bodies; Turkey-Cocks and Pheasants fly at a red Rag; a Rattle-Snake, by a sort of magical Power in his Eyes (as it is said) will force a Squirrel to run into his Mouth; Musick will cure the Bite of a Tarantula; the Frights and Longings of Women with Child, will stamp Impressions upon the Babes within them; People, in their Sleep, will walk securely over Precipices, and the Ridges of Houses, where they durst not venture, when awake; Lightning will melt a Sword without hurting the Scabbard.
John Trenchard and Thomas Gordon were also the authors of Cato’s Letters (London: Printed for W. Wilkins, T. Woodward, J. Walthoe, junr. and J. Peele, 1724)—one of those letters contains the following:
Men, like other Animals, are caught by Springs, Wires, or Subtilties: Foxes are trapann’d by Traces, Pheasants by a red Rag, and other Birds by a Whistle; and the same is true of Mankind.
The earliest occurrences of the phrase like a red rag that I have found are:
1-: From a speech delivered by Francis Burdett (1770-1844) at the House of Commons on Monday 13th March 1809—as transcribed in History of the proceedings of the House of Commons, in the inquiry into the conduct of his Royal Highness the Duke of York (London: Printed for John Stockdale, 1809):
The legal gentlemen […] were defeated by the proofs which stared them in the face—they were disarmed of their stings. Truth to a lawyer was like a red rag to a viper, it extracted his venom.
2-: From Glengarry versus the Celtic Society, by John Wilson (1785-1854), published under the pseudonym of Christopher North in Blackwood’s Edinburgh Magazine (Edinburgh: William Blackwood) of September 1822:
Where, in God’s name, we thought, is the unfortunate Glengarry? He must be swallowed alive now, for the Bulls of Bashan are all roaring against him, and will toss and tear him to pieces like a red rag.
3-: From Sam Pogson’s jealousy, or, Major Bunce. A chapter from Sam Pogson’s unpublished biography, published in Tait’s Edinburgh Magazine (Edinburgh: William Tait) of March 1836:
“Consarn them red coarts!” was Samuel’s first exclamation;—“they catch wimmin’s eyes like a red rag to a bull.”
4-: From The Standard (London, England) of Friday 15th September 1837:
The friends and supporters of Sir T. B. Hepburn, the Conservative candidate for the Haddington district of burghs, entertained him at a public dinner in the Assembly Room, Dunbar, on Tuesday last. […]
The noble Chairman […] said […] if a topic is wanted, or a cheer to be raised, “Tory” is pronounced, and, like a red rag shaken to a turkey-cock, the signal sets the whole assemblage in an uproar. (Loud cheers and laughter.) “Tory” is the spell which is to sweep everything before it—the “open Sesame,” which is to secure every avenue to election and office.
The phrase like a red rag to a bull is conflated with the phrase like a bull in a china shop in the following from The Red Rag (London: Richard Bentley and Son, 1880), a novel by the British author Richard Mounteney Jephson (1842–1906):
“My new assistant is emptying half the cellar of port, and champagne, and beer, and sending it away,” mumbled old Spigot. “I’ve been trying to stop him, but of course he can’t hear what I tell him. One would think old Fireworks was going to treat a regiment of soldiers. O lor’, O lor’, that’s likely! He, he, he! it makes me laugh, the very idea. Why, a soldier to him is like a red rag in a china-shop. He, he, he!”