At the end of a ggplot, this works fine:
+ opts(title = expression("Chart chart_title..."))
But this does not:
chart_title = "foo" + opts(title = expression(chart_title))
nor this:
chart_title = "foo" + opts(title = chart_title)
How can I add a title to a ggplot when the title is a variable name?
Adding a title To add a title to your plot, add the code +ggtitle("Your Title Here") to your line of basic ggplot code. Ensure you have quotation marks at the start and end of your title. If you have a particulary long title that would work better on two lines, use \n for a new line.
To change the size of the title and subtitle, we add the theme() function to labs() or ggtitle() function, whatever you used. Here we use labs() function. Inside theme() function, we use plot. title parameter for doing changes in the title of plot and plot.
Opts is being deprecated. One option is to use labs()
myTitle <- "My title" qplot(mpg, wt, data = mtcars) + labs(title = myTitle)
Pretty much the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With