how to switch desktop environment from terminal (remote access)?

On MY Ubuntu 16.04.4, I would stop the xfce service and start gdm3. See man service, and use sudo service --status-all to make sure the xfce service is running, then:

sudo service xfce stop
sudo service xfce status
sudo service gdm3 start
sudo service gdm3 status