The origin is a hard one to answer! But,
Margaret can easily become
Maggie, which drops the R;
Maggie or Mag becomes
Meg, which is or used to be the preferred Scottish nickname form, and
Peg rhymes with
Meg! The same kindof thing happened with
Mary, which became
Molly (R is a hard sound for children, and most nicknames come from other children in the family who can't quite get their young tongues round the new sibling's real name) and then
Polly. For boys,
Robert to
Bob is similar, I think.