Selection in a fluctuating environment leads to decreased genetic variation and facilitates the evolution of phenotypic plasticity