Sexual orientation is genetic, but it is also influenced by environment. That is, it has genetic components, but scientists have not identified an exact gay gene for it yet, just areas of the genome that influence sexual orientation.
Take a similar example: handedness. Whether you are right-handed or left-handed is highly influenced by genetics. However, you can train yourself to become more "left-handed" or more "right-handed" based on practice, environment, and on activities that you are skilled in, involved in, or interested in. For example, if you are right-handed and learn to play the piano, you will inevitably also learn to become left-handed, or more ambidextrous in that activity.
That is why if two men are on a desert island, even if they are more toward the "heterosexual" side of the Kinsey scale, they might end up deriving sexual pleasure from each other regardless, due to a lack of other sexual options.