Understanding pig behavior is like understanding the behavior of any animal. It means understanding the animal's physiology, psychology, and how it evolved. All these factors combine to create behaviors. All animals require food, water, living space, and companionship (this may only be for a short time, to propagate the species, but still required unless the "animal" is an amoebae)! Meeting these needs is what defines the behavior observed.
Physiology of pigs is important. They have no sweat glands and have trouble cooling their bodies, so can quickly overheat. This is why pigs stay in damp areas and mud, they are "chilling out". The mud directly adsorbs the heat and increases evaporative cooling. Pigs can also adsorb minerals through their noses (so can people!) and so they root or dig with their snouts. While doing this, they also find edible roots, buried acorns, and even grubs, so get fed. This means that pigs stay muddy and dig a lot, it is a behavior as a result of their physiology.
Psychology of pigs means the way they think, and all animals think to some extent, even humans. Pigs are very intelligent and learn quickly, much quicker than dogs. This means that they are extremely adaptable. Pigs stranded on small islands learned to catch fish, eat crabs and survived in areas where humans didn't. This also means do not show a pig a weak spot in a fence, it will remember and plot out escape routes! Pigs are escape artists because people show them the way!
Pigs evolved with the males fighting over the females, and females learned that because piglets are intelligent they become curious, poking their snouts in places they shouldn't, piglets need protection. This means pigs can be aggressive. A boars tusks are made to rip and tear another boar, they can mangle a dog or human just as well. Mothers protect their offspring and the younger the offspring the more fierce the mother, never get between a mother sow and young piglets!
Digging and lying in mud are due to physiology while adapting and escaping a result of training and psychology. Evolution easily accounts for the aggression for which swine are known. Remembering and studying those factors will help to understand pig behavior, just as they help with the understanding of all animal behavior. They helped create it!
If only human behavior was as easy to decipher, life would be so much simpler!