Highlight positive infinity symbol and negative infinity symbol

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

Here is my R code (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  ) ) ) 

      

+3


source to share


2 answers


Try:



text(c(-4, 6 ), rep(1, 2), c( bquote("- \U221E"), bquote("\U221E") ) ) 

      

+2


source


?plotmath

starts up

If the argument text

to one function of drawing text ( text

, mtext

, axis

, legend

) in the expression of R, the argument is interpreted as a mathematical expression, and the output will be formatted according to rules like TeX.

and the parameter is labels

text

documented as

a character vector or expression that defines the text to be written. an attempt is made to coerce other language objects (names and calls) to expressions, vectors and other classified objects to character vectors on as.character

.

(emphasis mine). bquote

does not actually return an expression (class R, not a concept), but a language object (call, in particular). This causes two problems:



  • Since R cannot handle a call vector, c

    it does not actually create a vector, but instead coerces the result into a list, akin to c(sum, mean)

    coercing a list, and
  • While it text

    will force the call returned from itself bquote

    into an expression (which will parse correctly), it will force the list into a character vector that is not interpreted according to plotmath

    .

You can force the list of calls created with c

and bquote

with as.expression

, but it's faster to just call expression

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)) 

      

infinity chart

As a final note, c

really works on multiple sort-in statements that c(expression(-infinity), expression(infinity))

return expression(-infinity, infinity)

. Unlike bquote

, which has two named parameters, expression

accepts ...

though, so it's easier to just call it once with multiple inputs.

+7


source







All Articles