Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plot the positive infinity symbol and negative infinity symbol

Tags:

plot

r

plotmath

I was wondering how I can plot the positive infinity sign and -Infinity sign in plot?

Here is my R code (with no success):

plot(1, ty ='n', ann = F, xlim = c(-4, 6), ylim = c(-3.5, 1.5) )

text(c(-4, 6 ), rep(1, 2), c( bquote(- infinity  ), bquote(infinity  ) ) ) 
like image 245
rnorouzian Avatar asked Mar 26 '17 20:03

rnorouzian


People also ask

Where is negative and positive infinity on a graph?

Notice that the y-values on the graph go from negative infinity ( the lowest point of the graph) and to positive infinity (the top of the graph).

What is the symbol for negative infinity?

The most interesting thing about infinity is – ∞ < x < ∞, which is the mathematical shorthand for the negative infinity which is less than any real number and the positive infinity which is greater than the real number.

How do you type ∞?

Hold one of the alt keys available right and left side of the shift key. Type 8734 using number pad on your keyboard. This will make the infinity symbol ∞.


2 Answers

?plotmath starts

If the text argument to one of the text-drawing functions (text, mtext, axis, legend) in R is an expression, the argument is interpreted as a mathematical expression and the output will be formatted according to TeX-like rules.

and the labels parameter of text is documented as

a character vector or expression specifying the text to be written. An attempt is made to coerce other language objects (names and calls) to expressions, and vectors and other classed objects to character vectors by as.character.

(emphasis mine). bquote does not actually return an expression (the R class, not the concept), but a language object (a call, specifically). This is causing two problems:

  • Because R can't handle a vector of calls, c does not actually create a vector, but instead coerces the result to a list, akin to how c(sum, mean) is coerced to a list, and
  • While text would coerce the call returned from bquote itself to an expression (which would get parsed properly), it coerces the list to a character vector, which does not get interpreted according to plotmath.

You could coerce the list of calls produced with c and bquote explicitly with as.expression, but it's quicker to just call expression directly and avoid bquote altogether:

plot(1, ty ='n', ann = F, xlim = c(-4, 6), ylim = c(-3.5, 1.5))

text(c(-4, 6 ), rep(1, 2), expression(-infinity, infinity)) 

plot with infinity symbols

As an end note, c actually does work on multiple expressions—sort of—in that c(expression(-infinity), expression(infinity)) returns expression(-infinity, infinity). Unlike bquote, which has two named parameters, expression takes ... though, so it's easier to just call it once with multiple inputs.

like image 93
alistaire Avatar answered Oct 06 '22 06:10

alistaire


Try:

text(c(-4, 6 ), rep(1, 2), c( bquote("- \U221E"), bquote("\U221E") ) ) 
like image 34
G5W Avatar answered Oct 06 '22 06:10

G5W