Adaptation to marginal habitats by evolution of increased phenotypic plasticity