I would like to have the title for the plot in two lines, but this does not work, why? and how can I make it work?
CVal<-1
SumEpsVal<-2
plot(1:10, main=bquote(paste("C=", .(CVal), " \n ", sum(xi), "=", .(SumEpsVal) )))
This here works:
plot(1:10, main=paste("C=1", "\n", "SumXi=2"))
I guess bquote makes something wrong... (look up ?bquote) I tried to change environment in bqoute (the where-argument) but I don't know which environment to take.
BTW:
plot(1:10, main=bquote(paste("C=", .(CVal), "bla \n ", sum(xi), "=", .(SumEpsVal) )))
makes something crazy with the "bla".
There are two possible ways to do that : Directly by specifying the titles to the plotting function (ex : plot() ). In this case titles are modified during the creation of plot. the title() function can also be used.
It is a common need to set the title in several lines. To add a break in the title, simply write '\n' in the text.
Use 'wrap_labs()' to wrap the title, subtitle, and caption of a ggplot2 chart onto multiple lines, left-align them, and split 'notes' and 'source' onto multiple lines.
This is done by separating each string line of text with a comma and enclosing all comma-separated strings in curly braces as follows. The 10 outside the single quotes is the ascii value for a newline.
Personally I would use mtext as already suggested. But if you really want it to be a one-liner, you can "cheat" bquote
by using atop
:
plot(1:10, main=
bquote(atop(paste("C=",.(CVal)), paste(sum(xi),"=",.(SumEpsVal)))))
It even aligns both lines neatly to the center.
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