I've left games amicably, and I've left games under less-happy circumstances. There is, quite simply, no one single "best" way to do it.
If the game just isn't fun for me, I'll raise the concern with the group as a whole. If the rest of the folks are satisfied with the status quo, I'll bid a friendly "maybe next campaign" farewell.
If I have a personal conflict with someone, I'll explain that to the GM (even if they are that someone) in as non-accusatory terms as i can. A favorite of mine is a line another gamer came up with: "Role playing attracts strong personalities. Strong personalities often clash." I'll then suggest I do the graceful thing, and remove myself from the situation so as to preserve everyone else's enjoyment.
...
But, then, sometimes none of that works. Or something goes so horribly wrong, that I stop caring about making a graceful exit.
Even then, I don't shout, or swear, or hurl insults. I just quietly pak up my things, stand up, and
WALK AWAY. If I can't trust myself to keep my temper when addressing anyone, I
don't address anyone. Silence is preferable to saying something hurtful.
That happened once, in a game run by a good friend. Tempers were frayed, things were said (not by me), the GM lost her cool at me ... and ... I'd simply had bloody well enough. I packed up my things, walked out, and gave it a day or two for things to cool down. I didn't rejoin that campaign, though, because I'd seen that the group was just too big and problems like those were just going to happen again.
And a couple years later, when the same friend was running several
smaller groups, each on different days, I quite happily accepted an invitation to one of them. Because even though we were both clearly very upset (and I was clearly quite angry with her at the time),
I did not let myself say things I would later regret....
Plus, you know? No matter how ticked off I am at someone in a gaming group, I won't hurl petty and puerile insults when leaving a game/group because (a) I don't want to build a reputation among local games as generally being an ass, and (b) reputation or not,
I'm just better than that.