How to rotate the axis labels in ggplot2?

ggplot2, r

Solution

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))

Problem

I have the following graph that I generated using ggplot2 I had `finalPlot` as the ggplot object. To add labels I used ``` finalPlot + stat_bin() + scale_x_continuous('Solution Cost') + scale_y_continuous('Number of Solutions')` ``` How can I change the orientation of the y axis label to make it appear horizontal and if possible span it across two lines like ``` Number of Solutions ```

Original source

Related problems