The Origins of Scaling in Cities