This is such an incredible poem about how to live one's life, and it contains some great figurative language to create a tone of encouragement. Here are a few examples:
The repetition of "If you can" at the beginning of many lines serves as a reminder of what is possible. It is not easy to be lied about and "not deal in lies." It is difficult to "trust yourself when all men doubt you." But by using anaphora in this key phrase, the reader is provided with hope for difficult circumstances.
The speaker personifies Triumph and Disaster, noting that they are both "impostors." His takeaway here is that both victory and devastation have undue power over people's lives at times. Both are temporary situations, and no one should put too much faith in the outcomes of the extreme highs or lows in life.
In the opening line, the speaker notes, "If you can keep your head." The use of "head" in this line is actually a substitution for another, similar idea. He really means that "if you can keep a calm mind." This ability to substitute one thing (a head) for a similar concept (a calm mind) is known as metonymy.
In the line "If neither foes nor loving friends can hurt you," the speaker juxtaposes two opposite ideas (foes and friends) by using the same f initial sound. He does this to show the commonalities of two seemingly contradictory groups of people. We are easily convinced that a foe could hurt us, but the power which friends have to hurt us is actually far greater because we have granted these people access to our trust and inner thoughts. Through alliteration, the speaker more closely links these ideas in our mind than would be possible if he had used words with different initial sounds (like enemies and friends).
The figurative language that runs throughout "If—" gives it a rich depth. The poem serves as a reminder of how we should strive to live our lives in the best ways possible.