mas2
mas2

Reputation: 65

Adding additional text above y-label in ggplot

I'm making a big plot to compare forecast-models. But how can one add additional text to a label? For example this is one of the plots that I need additional text beside the y-label.

(qplot(y = VaR90_n_roll1, x = 507:1006, geom = 'line')
                     + geom_line(color = 'green')
                     + geom_point(aes(x = 507:1006, y = sp500_logreturns[507:1006]))
                     + coord_cartesian(ylim = c(-0.065,0.05))
                     + labs(y = c('Log returns', 
                            'Model 1'), x = '')
                     + ggtitle("")
                     + theme(plot.title = element_text(hjust = 0.5)))

Which gives me this: enter image description here

But I need this: enter image description here

Upvotes: 0

Views: 53

Answers (1)

Peter
Peter

Reputation: 12699

It this what you are looking for?

library(ggplot2)

ggplot(mtcars, aes(wt, mpg))+
  geom_point()+
  labs(y = expression(atop(bold(Model~1), scriptstyle(Log~returns))))+
  theme(axis.title.y = element_text(size = 14))

Created on 2020-05-24 by the reprex package (v0.3.0)

Upvotes: 3

Related Questions