It came about in exactly the same way as William became Will which became Bill and Richard became Rick which became Dick over a long period of time...in other words by shortening and playfully changing the opening letter. Thus, Margaret became Maggie/Meggie which became Peggy.