Questions tagged [plotmath]

plotmath provides mathematical expression plotting in the R language.

Arguments to the text plotting functions in (text, mtext, axis, legend) accept both character and expression arguments. Character values are drawn to the plot as-is, while expressions are evaluated according plotmath rules. These rules differ from those for typical R expressions (see documentation).

169 questions
5
votes
2 answers

Plot the positive infinity symbol and negative infinity symbol

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 ),…
rnorouzian
  • 7,397
  • 5
  • 27
  • 72
5
votes
3 answers

How to align title and subtitle in ggplot2 when generated via expression

I'm using the code below to generate a simple box plot in ggplot2: # Libs data data("mtcars"); require(ggplot2); require(ggthemes) # Chart ggplot(data = mtcars) + geom_boxplot(aes(y = wt, x = as.factor(am)), fill = "gray87") + …
Konrad
  • 17,740
  • 16
  • 106
  • 167
5
votes
1 answer

Plot legend label in multiple lines including mathematical expressions

How can I create legend labels containing multiple lines of text followed by a mathematical expression on a separate line, avoiding the problems listed below? The accepted answer here doesn't work for legends, and as far as I can tell, the alternate…
baixiwei
  • 1,009
  • 4
  • 20
  • 27
5
votes
3 answers

How to use more than one expression in a row

I am new to R and I am trying to figure out, how to write something like "This is my plot for (\n)8 <=(less than or equal) x <= 10" in my plot-title. I tried something like this: plot(1:10, main="Hey, guys, this is my plot for…
Nzuri
  • 61
  • 2
5
votes
1 answer

Is there any way to get expression() to display P(a <= X <= b)?

I've mostly been able to coerce expression() into giving me the mathematical output I've needed for graphs, but I'm flummoxed by this one. text(-2,.21,expression(P(a <= X)), cex=1.2) gives me the expected result, but text(-2,.21,expression(P(a <= X…
pgoetz
  • 848
  • 1
  • 8
  • 18
4
votes
2 answers

R: How to mix a series of variables and Greek symbols in a string

Suppose x and y are variables. I am trying to create a graph title that has a Latex equivalent of $\sigma_v =$ 3 $\rho =$ 5, where the values 3 and 5 come from R variables. Here is the closest I have been able to come (modeled after an example in…
Robert McDonald
  • 1,250
  • 1
  • 12
  • 20
4
votes
1 answer

translate plotmath latex

I started using the awesome knitr package, and whilst I love the idea of using tikz graphics, it's not always very practical (time consuming). Thus, I end up switching back and forth between the good old pdf device, and tikz. Mathematical…
baptiste
  • 75,767
  • 19
  • 198
  • 294
4
votes
1 answer

bgroup does not render properly on ggplot

The results of bgroup from plotmath do not seem to render properly as a ggplot2 annotation. For example ... library(ggplot2) ggplot(mtcars, aes(wt, mpg)) + annotate("text", x=2.5, y=25, label="bgroup('(',atop(x,y),')')", parse=TRUE) + …
D Ogle
  • 407
  • 2
  • 13
4
votes
2 answers

How to write much less than symbol (<<) in plotmath in R?

I'm trying to write the << symbol in R but I'm not succeeding. Any tips? plot(expression(alpha<1)) plot(expression(alpha<<1)) Error: unexpected input in "plot(expression(alpha<<"
Daniel Valencia C.
  • 2,159
  • 2
  • 19
  • 38
4
votes
1 answer

Make row labels italic in heatmap.2

I'm trying to make my row labels italic using the R function heatmap.2. There's no default option and I can't figure out a work around by setting par(font=3) for example. How can I set my row labels to be italic in heatmap.2? set.seed(123) data =…
Erik
  • 123
  • 2
  • 7
4
votes
1 answer

Fully Left-Justify When Using atop()

How can I fully left-justify text when using atop()? library(tidyverse) mtcars %>% mutate(cyl = str_c("atop(bold(", cyl, "~long~text~on~the~top),(shorttext))")) %>% ggplot(aes(hp, wt)) + geom_line() + facet_wrap(~cyl, labeller =…
John-Henry
  • 1,556
  • 8
  • 20
4
votes
1 answer

How to concatenate two expressions?

How can two expressions (expr and alpha~"is in ") be combined so that they are shown as one expression (in a plot label or via mtext() or so)? expr <- expression(bgroup("(",frac(1,3)*", "*frac(1,2),")")) plot(0, 0, xlab = expression(c(alpha~"is in…
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
4
votes
1 answer

Use ampersand in ggplot facet strip label

How can I use an ampersand in a facet strip label? I have tried as is, and using unicode with the same result. MWE library(ggplot2) mtcars$am2 <- factor(mtcars$am, labels=c("N[one]==1 \U0026 N[one]==1", …
user2957945
  • 2,353
  • 2
  • 21
  • 40
4
votes
2 answers

Error when exporting ggplot graphs to pdf: invalid font type

I'm having trouble getting my plots to save using ggsave(). I keep getting this error: Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, : invalid font type I don't understand why I would be getting this error.. I'm not using…
NBE
  • 641
  • 2
  • 11
  • 33
4
votes
2 answers

How to use bquote in combination with ggplot2 geom_label?

I've read the following article: https://trinkerrstuff.wordpress.com/2018/03/15/2246/ Now I'm trying to use the suggested approach with bquote in my plot. However I can't get it to work. I have the following code x <- seq(0, 2*pi, 0.01) y <-…
katrasnikj
  • 3,151
  • 3
  • 16
  • 27