Highlight positive infinity symbol and negative infinity symbol
?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 toc(sum, mean)
coercing a list, and - While it
text
will force the call returned from itselfbquote
into an expression (which will parse correctly), it will force the list into a character vector that is not interpreted according toplotmath
.
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))
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.
source to share