R: plotmath expression characters that are not displayed in the interaction area

For some reason, my interaction graphs don't seem to show Greek characters (latex) in R markdown (using R studio). The code I use is reproduced below. Why don't expression () functions work? Any suggestions?

with(ba_results, interaction.plot(as.factor(f1), as.factor(f2), 
                                  y,
                                  type = "b",
                                  pch = c(18, 19, 24),
                                  fixed = TRUE,
                                  xlab = "Scale factor",
                                  ylab = "Mean Response",
                                  trace.label = expression(mu_e),
                                  main = paste("Interaction plot of", 
                                               expression(mu[e]), 
                                               "f1")))
+4
source share
1 answer

In the heading, wrap everything in expression. For example, main = expression(paste("Interaction plot of ", mu[e], " f1"))or main = expression(Interaction~plot~of~mu[e]~f1).

For trace.label, expressionnot handled properly. It seems like the problem is this line in the code for interaction.plot:

text(xleg, ylim[2L] - 0.05 * yrng, paste("  ", trace.label), adj = 0)

So it is trace.labelassured of paste, which returns the expression in a text string. For instance:

expression(mu[e])
# expression(mu[e])

paste("  ", expression(mu[e]))
# "   mu[e]"

trace.label . interaction.plot, interaction.plot . R script , my_interaction_plot. :

text(xleg, ylim[2L] - 0.05 * yrng, trace.label, adj = 0)

expression(mu[e]).

my_interaction_plot interaction.plot :

with(ba_results, 
     my_interaction_plot(as.factor(f1), as.factor(f2), y, type = "b",
                         pch = c(18, 19, 24), fixed = TRUE,
                         xlab = "Scale factor", ylab = "Mean Response",
                         trace.label = expression(mu_e),
                         main = expression(paste("Interaction plot of ", mu[e], " f1"))))
0

Source: https://habr.com/ru/post/1680268/


All Articles