How to rotate the axis labels in ggplot2?

前端 未结 2 1293
礼貌的吻别
礼貌的吻别 2020-12-16 20:26

I have the following graph that I generated using ggplot2 \"enter

I had finalPlo

相关标签:
2条回答
  • 2020-12-16 20:49

    For the rotation angle of the axis text you need to use element_text(). See this post on SO for some examples. For spacing over two lines I would add a "\n" on the location in the string where you want to put the newline.

    This will set the correct orientation for the y axis text and force a line break:

    finalPlot + ylab("Number of\nSolutions") + 
        theme(axis.title.y = element_text(angle = 0))
    
    0 讨论(0)
  • 2020-12-16 20:50

    The syntax has changed in recent versions of ggplot2; if you try the above answer, you'll get

    Error: Use 'theme' instead. (Defunct; last used in version 0.9.1)

    These days you should use

    finalPlot + ylab("Number of\nSolutions") + theme(axis.title.y = element_text(angle=0))
    
    0 讨论(0)
提交回复
热议问题