Steve G
Steve G

Reputation: 85

ggplot second line on y axis title not working

I cannot seem to get a second line no matter how I try to work it with the "\n" operator. I want some text, "TEST" to be on the second line. Any ideas how to make this work?

ytitle <- expression(bold(paste("Chlorophyll", italic(" a "), "(",mu, gL^-1,")", "\n TEST")))

ggplot(mtcars, aes(x=wt, y=mpg)) +
  geom_point(size=2, shape=23) + labs(y=ytitle)

enter image description here

Upvotes: 0

Views: 433

Answers (2)

Steve G
Steve G

Reputation: 85

My solution is here, thanks!

ggplot(mtcars, aes(x=wt, y=mpg)) +
      geom_point(size=2, shape=23) + labs(y=expression(atop(paste("Chlorophyll", italic(" a "), "(",mu, gL^-1,")"), "TEST")))

enter image description here

Upvotes: 0

Florian Muthreich
Florian Muthreich

Reputation: 11

You can use atop()

atop("above", "below")

simple atop example

Change your ytitle to this.

ytitle <- expression(bold(atop(paste("Chlorophyll", italic(" a "), "(",mu, gL^-1,")"), "\n TEST")))

Your y-axis label

Upvotes: 1

Related Questions