R – How to rotate the axis labels in ggplot2

ggplot2r

I have the following graph that I generated using ggplot2 enter image description here

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

Best Answer

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