Non alpha character arrowlabels on a diagram

2019-07-18 20:43发布

问题:

The R package diagram has been giving me some very nice flow charts. Here is a simple example:

install.packages("diagram")
require(diagram)
A = matrix(nrow = 2, ncol = 2, data = 0)
A[2,1] = "hello"
par(xpd = NA)
plotmat(A, name = c("A", "B"))

I would like to change the arrowlabel (currently set as "hello") to be "(+)". So,

A[2,1] = "(+)"
plotmat(A, name = c("A", "B"))

But this fails:

Error in parse(text = x, ...) : <text>:1:3: unexpected ')'
1: (+)
     ^

Is there a set of escape characters, or some other trick, that will force parse to interpret my symbols as simple text? Of course, a workaround is to use text to place text on the plot, but I'm hoping to take advantage of plotmat's built-in label positioning functionality.

回答1:

Try

A[2,1] = "`(+)`"
plotmat(A, name = c("A", "B"))



标签: r diagram labels