It is recommended to avoid swimming for at least four weeks after a hair transplant to prevent infections and protect the healing grafts.