ggplot2 - two or more lines on y axis title

Viewed 694

I need two or more lines of text on my y-axis title. However, the title is cut off if I have multiple lines. Anyway I can work around this?

ggplot(iris,aes(Sepal.Length, Sepal.Width)) +geom_line()+labs(y=expression(paste("line 1 \nline2")))

enter image description here

2 Answers

Play with plot.margin in theme to change the whitespace around your plot

ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
  geom_line() +
  labs(y = expression(paste("line 1\nline2"))) +
  theme(plot.margin = margin(1, 1, 1, 1, "cm")
  )

enter image description here

We can use ylab

library(ggplot2)
ggplot(iris,aes(Sepal.Length, Sepal.Width)) +
  geom_line()+
  ylab(bquote("Mean Annual \nAir Temperature"~degree*"C")) +   
  theme(plot.margin = margin(1, 1, 0.5, 0.5, "cm"))

-output

enter image description here

Related