Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot main title in two lines

Tags:

r

plotmath

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".

like image 261
Giuseppe Avatar asked Jan 03 '13 08:01

Giuseppe


People also ask

How do you add title on the plot?

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.

How do you break a title in R?

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.

How do you wrap a title in a graph in R?

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.

How do I add a new line to a title in Matlab?

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.


1 Answers

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.

like image 158
Theodore Lytras Avatar answered Oct 06 '22 07:10

Theodore Lytras