The design dates back to 1890 and was part of a larger trend toward workers of specific trades choosing their own distinctive apparel, or uniforms. Since train engineers were affectionately known as "hog heads", their distinctive hats became known as "hog head hats".
Originally, the hats were made of dark-colored denim, but in 1920, a Wisconsin clothing manufacturer offered hats of that design made of blue-and-white striped material, as a promotion to encourage sales of their overalls, which were also made of that material. The combination of blue-and-white striped caps and overalls became the standard apparel of train engine crews throughout the remaining years of the steam-engine era and into the era of diesel- and electric-powered locomotives.
* Blue/white stripe work shirts are made of "hickory cloth", which may be related to railroad clothing somehow, from what I find online.
From the early 1940s until the mid-1980s the Lee company was the industry standard for the Hickory shirt, button front or zip. It also is called the railroad shirt and the fabric is known as hickory fabric, a relative of denim and as durable as hickory wood. One could say this is the shirt that built this country.