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
2
votes
1 answer

how to add symbols or signs like ≤ or ≠ to a legend or axis in R

I want to add the symbol ≤ in to a legend in R as in ..."≤1",col="gray"... but when I run the script it creates and = symbol as if I have typed ..."=1",col="gray"... Is there a way I can tell R I want that ≤ symbol? And to help anyone with a…
rg255
  • 4,119
  • 3
  • 22
  • 40
2
votes
1 answer

r label plots with fractions

I would like to create 3 plots each containing a plot of 2 lines from different data frames, and then label each plot with a specific fraction. So for example I have the 3 data frames: df1 <- data.frame(x=c(1,2,3,4),y=c(2,3,4,5), z=c(3,3,6,8)) df2…
user971102
  • 3,005
  • 4
  • 30
  • 37
2
votes
1 answer

Transform numbers with exponents to plotmath commands for beautiful legends in R

I'm trying to generate a beautiful legend in R plots. I have a factor=1e-5, that should appear nicely formatted in the legend. I found a nice function in the package sfsmisc, that transforms numbers to expressions. To add this expression to my…
R_User
  • 10,682
  • 25
  • 79
  • 120
2
votes
1 answer

use two variables and an expression within a plotmath()

I would like to do something like this: Title<-paste(typis[which.panel],bquote(nu[x]==.(typas[which.panel])),sep="") where typas is a vector of numbers and typis a vector of chars e.g.: typas<-1:3 typis<-letters[1:3] which.panel is an integer in…
user189035
  • 5,589
  • 13
  • 52
  • 112
2
votes
1 answer

plot() and do.call(): How to pass expressions to plot title when '...' is used otherwise?

When run the following code, I obtain Error in as.graphicsAnnot(text) : could not find function "bold". How can I fix this? my.qq <- function(x, main=expression(bold(italic(F)~~"Q-Q plot")), margs=list(side=3, cex=par("cex.main"),…
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
2
votes
1 answer

Chemical formula (or mathematical expression) in GNU R plot title

How can i write H2o in the title of a plot? H2 works: plot(main=expression("H"[2]),0) H2O fails: plot(main=expression("H"[2]"O"),0) This solution will work only, if i have a space in front " " plot(main=expression(" "*H[2]*"O"),0)
Jonas Stein
  • 6,826
  • 7
  • 40
  • 72
1
vote
0 answers

Is it possible to use ggtext to plot symbols on top of each other?

I try to use geom_richtext of the "ggtext" package to create my labels and I want to plot a number and a letter on top of each other. But I don't know whether this is even possible with "ggtext" yet. I could only achieve the desired layout with the…
maRvin
  • 249
  • 1
  • 11
1
vote
1 answer

Line break in expression of table header?

I have seen a number of similar questions relating to line breaks in expressions, but I'm still not able to get a table with an expression and line break in the header. I would like it to say Model R2 on the top line, and Mean (95% CIs) on the…
Jeff
  • 57
  • 6
1
vote
1 answer

Using plotmath with geom_label_repel to have subscripts within the labels

I am trying to have subscripts in my geom_label. e.g. Maine Apo (km/h) = 9 Qt (m/s) = 90 I am aware of using [x] to get subscripts but I am not sure how to achieve that when I want to get the label values (partly) from a column. I tried using…
M--
  • 25,431
  • 8
  • 61
  • 93
1
vote
2 answers

Is it possible to use == twice in R mathematical notation?

I am trying to use R mathematical notation of plotmath in a plot label. In the label, I am trying to use to equality signs, e.g. ggplot(data=NULL) + geom_point(aes(x=0.5, y=0)) + geom_text(aes(x=0.5, y=-0.1), label = paste("x ==…
Lukas D. Sauer
  • 355
  • 2
  • 11
1
vote
1 answer

How can I strip a leading zero from an expression rendered by plotmath?

Due to a journal's requirements, I need to format p values as capital, italic P and the values themselves without leading zero, for example, P = .01. I would like to include some p value labels in plots of mine. My trouble is that I need to use…
Midnighter
  • 3,771
  • 2
  • 29
  • 43
1
vote
1 answer

Poorly typeset μ symbol in plotmath

When using the default font (sans) in base R, symbols like μ are poorly typeset: plot(1, xlab = bquote("I want sans font here, but serif font for:" ~ (mu * g))) The g looks larger than the μ symbol. Setting the font family to serif somewhat…
Frans Rodenburg
  • 476
  • 6
  • 17
1
vote
1 answer

How to format p-values in ggplot2 `annotate()`—APA style?

I would like to add a p-value to a scatter-plot, while respecting APA style. This entails two elements: (a) an italicized p, and (b) stripping the leading zero (but also: formatting values smaller than .001 as < .001). We can strip the leading zero…
rempsyc
  • 785
  • 5
  • 24
1
vote
1 answer

Functions to format text for base R plotting

Specifying text in a base R plot() with formatting such as italics / bold font / newline usually involves one or more of the following functions: paste() expression() atop() substitute() italic() Is there an intuitive explanation for the…
FlamingGoose
  • 153
  • 1
  • 9
1
vote
1 answer

ggplot2 axis text formatting won't work with exponents

It is easy enough to change the axis text of a ggplot to some sort of expression (in this case 10^.x). However, when the text is transformed, it loses bold formatting. I was wondering if there was a way to retain bold formatting but also have the…
csdaw
  • 63
  • 6