For 90 degree rotation of the display
sudo nano /boot/config.txt
add line (#1: 90; 2: 180; 3: 270)
display_rotate=1
For 90 degree rotation of the touchscreen
sudo apt-get install xserver-xorg-input-libinput
sudo mkdir /etc/X11/xorg.conf.d
sudo cp /usr/share/X11/xorg.conf.d/40-libinput.conf /etc/X11/xorg.conf.d/
sudo nano /etc/X11/xorg.conf.d/40-libinput.conf
In the touchscreen block, add (90 degree: Option “CalibrationMatrix” “0 1 0 -1 0 1 0 0 1”, 180 degree: Option “CalibrationMatrix” “-1 0 1 0 -1 1 0 0 1”, 270 degree: Option “CalibrationMatrix” “0 -1 1 1 0 0 0 0 1” )
Option "CalibrationMatrix" "0 1 0 -1 0 1 0 0 1"
sudo reboot