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

Reduce spacing of frac in R expression for ggplot legend

I am trying to reduce the space between the numerator, denominator, and fraction line in R expression. Here is my MWE generating a very ugly legend text for the fraction: tibble( t = seq(0,60,.1), osc = cos(log2(1+t)*pi+pi/4) ) %>% …
Baraliuh
  • 2,009
  • 5
  • 11
0
votes
1 answer

Using paste() and formatC() together in plot label in R

I want to use a subscript and a number in a geom_text() layer of a ggplot2 plot. The number will come from an indexed dataframe so that I can use it in a flexible way within a custom function, but here is a simpler reproducible example: temp_line <-…
user2860703
  • 483
  • 5
  • 18
0
votes
2 answers

R plotmath expression to show range of values in ggplot

I am struggling to get expression to communicate something like 10<=VarName<120. Why does the following code fail? starwars %>% filter(between(birth_year, 10, 120)) %>% ggplot(aes(x=mass, y=height)) + geom_point() + …
0
votes
1 answer

Two-line annotations using plotmath expressions in ggplot

I want to italicise a single character in the second line of a annotation in ggplot Here's the plot iris %>% ggplot(aes(x = Sepal.Length, y = Species, fill = Species)) + stat_summary(geom = "bar", fun = "mean")…
llewmills
  • 2,959
  • 3
  • 31
  • 58
0
votes
1 answer

How to add a title with greek letters to a Plotly graph with R?

library(plotly) f <- plot_ly(alpha = 0.5) %>% add_histogram(x=rnorm(1000), name="Observed", marker=list(color="darkolivegreen") ) ) f %>%…
Paw in Data
  • 1,262
  • 2
  • 14
  • 32
0
votes
1 answer

How do I bold and underline part of a ggplot2 annotation?

I am trying to use the bold() and underline() functions from grDevices within paste() to create an annotation that features a stylized, hardcoded 'title' with a line break followed by a string that could be one or more lines long, and am struggling…
Bryce R.
  • 11
  • 3
0
votes
2 answers

boldface of labels containing an expression with lower or equal symbol

I need to render in boldface the labels of the legend of a graph. One of the labels is an expression containing a "lower or equal" sign. This is where I started from: library(ggplot2) df <- data.frame(x=factor(rep(0:1, 10)), y=rnorm(10),…
Claudio
  • 1,229
  • 6
  • 11
0
votes
0 answers

How to use italic in label_bquote for strip text lables

There have been many proposed solutions to many slightly different problems, but none quite catches my specific problem. What I want is the following: I want to mix normal subfig labels (a, b, c, ...) with species names in italics. So far, I only…
bamphe
  • 328
  • 3
  • 12
0
votes
1 answer

Use plotmath to write superscript inside exponentiated brace, e.g., a Poisson-like multiplicative equation

How might I use plotmath capabilities to add a multiplicative Poisson-like equation to my plot? Or, given that I'm really close, how can I write this equation without the . in the middle of the exponent? I tried phantom but it didn't work (or I'm…
jasmyace
  • 101
  • 1
  • 7
0
votes
0 answers

R: "plotmath" produces extra white space when using Computer Modern fonts

More specifically, the "juxtapose" feature [i.e. "*" or "paste"] produces extra white space when using the "CM Roman" font family. With other families [e.g. "CenturySch"] it works fine. An issue of R [using 3.0.2]? Or invalid font source file? A MWE…
0
votes
2 answers

Equal spacing with multiple atop

I'm trying to create a legend in a ggplot2 graph with multiple lines and a parameter and value on each line. Since I have symbols as variables, this needs to be done with expression. To create new lines, I have used multiple atop commands, but this…
tkmckenzie
  • 1,353
  • 1
  • 10
  • 19
0
votes
1 answer

Plotmath symbol and reference to a variable in R plot legend: possible without Unicode character?

I am trying to make a label in a base R plot legend that has a greater than or equal to sign followed by a numeric value that is gathered from a variable. I can do this with the following code using the Unicode character, and the bquote…
Jared Smith
  • 280
  • 3
  • 12
0
votes
1 answer

Using % as subscript in plotmath

How can I use the percent symbol as subscript in a plotmath expression? I am using the following script: text(4.2,0.45, expression(paste(P[Con_30%Fat], "=0.611")), cex = 1.3) and I get the following error: Error: unexpected input in "text(4.2,0.45,…
VasoGene
  • 141
  • 3
  • 12
0
votes
1 answer

Superscript/subscript in R

I would like to have on a plot the following: I am using this code, but I don't get the expected outcome. text(4.4,0.5, expression(paste(P[B6.Rag^"-/-"_NOD.Rag^"-/-"], "=2.9x10^-4")), cex = 1.3) Thanks
VasoGene
  • 141
  • 3
  • 12
0
votes
1 answer

Multiple indices in ggplot label

I would like to add a label containing multiple indices to a bar plot: data<-as.data.frame(c("A")) colnames(data)<-"A" data$B<-5 ggplot(data, aes(x=A, y=B)) + geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8,…
user2568648
  • 3,001
  • 8
  • 35
  • 52
1 2 3
11
12