Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subscripts in plots in R

Tags:

plot

r

subscript

I can't find a way how to write subscripts in the title or the subtitle in R. How can I write v 1,2 with 1,2 as subscripts?

Thanks for your help!

like image 530
jeffrey Avatar asked Apr 14 '12 18:04

jeffrey


People also ask

How do you subscript in R plot?

Subscripts and Superscripts To indicate a subscript, use the underscore _ character. To indicate a superscript, use a single caret character ^ . Note: this can be confusing, because the R Markdown language delimits superscripts with two carets.

What are subscripts in R?

R doesn't actually have scalar types; everything is a vector, so subscripts are vectors. In the expression x[2] , the subscript is a vector containing a single element equal to 2. But you could use the vector (2, 3) as a subscript of x , and you'd get (1, 4).

How do you do a superscript in ggplot2?

To add superscript as a title add bquote function with value inside ggtitle(). Parameter : like xlab and ylab functions, we can give the title for plot directly using this function. Here we will bquote() function for writing Superscript value ( Number VS Number2 ) as a title of plot.

How do you use YLAB and XLAB in R?

To set labels for X and Y axes in R plot, call plot() function and along with the data to be plot, pass required string values for the X and Y axes labels to the “xlab” and “ylab” parameters respectively. By default X-axis label is set to “x”, and Y-axis label is set to “y”.


2 Answers

expression is your friend:

plot(1,1, main=expression('title'^2))  #superscript plot(1,1, main=expression('title'[2])) #subscript 
like image 102
smu Avatar answered Sep 24 '22 19:09

smu


If you are looking to have multiple subscripts in one text then use the star(*) to separate the sections:

plot(1:10, xlab=expression('hi'[5]*'there'[6]^8*'you'[2])) 
like image 38
Cyrille Avatar answered Sep 23 '22 19:09

Cyrille