Yes, you want it in a stud. If a stud is not in the location you want you can bridge between 2 studs with a piece of wood and then position the handle anywhere you want. You can also buy a grab bar at a big box store that is 16" long and attach it to 2 studs. Or 24" long and angle it between 2 studs.
If you are placing it vertically, you want it in a stud.
And sometimes you can plan for the future...Anytime I redo a shower I put studding in for a future grab bar and send a pic to the customer. I do this behind tile or surround. A few extra minutes of my time might save one person from a bad problem in the future.Sometimes I have opened a wall up and sistered a 2 X 6 to studs in order to mount a grab handle securely to a wall. IMHO, you can't make them too strong.
