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
12
votes
2 answers

properly formatting a two-line caption in ggplot2

I am working on a custom function that can add two-line captions to plots and I want the caption to be formatted properly no matter what the user might choose to enter ("character" or "expression"). I have created a toy example below to illustrate…
Indrajeet Patil
  • 4,673
  • 2
  • 20
  • 51
12
votes
3 answers

Include text control characters in plotmath expressions

Is there any way to get control characters for text strings, e.g. "\n" for newline evaluated inside a plotmath expression, or vice versa. In the following example, I would like to combine: some character text text control character…
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
11
votes
1 answer

Using plotmath in ggplot2 with percent sign (%)

I would like to use Greek characters, Latin characters and the percent sign in the facet labels of a ggplot2 bar chart. Greek characters can be done with 'facet_grid(.~variable, labeller=label_parsed)': …
Robert
  • 217
  • 2
  • 10
11
votes
2 answers

Subscripts in R when adding other text

How would you add a subscript to one particular word of a title in R? For example, suppose the title is "A_2 and B_2." How would you add these two subscripts? I know that expression("A"[2]) and expression("B"[2]) individually add subscripts to these…
Damien
  • 382
  • 3
  • 8
  • 17
10
votes
1 answer

Line break in ggplot annotate with LateX expression

SITUATION: I have a ggplot diagram, where I want to add some text annotation. The text annotation should appear in two lines (for readibility and space), and each line includes some TeX formula: library(tidyverse) library(latex2exp) ggplot(NULL,…
Sebastian Sauer
  • 1,555
  • 15
  • 24
10
votes
1 answer

Using italic() with a variable in ggplot2 title expression

When I make a map using ggplot2 and attempt to italicize part of the figure title using a combination of expression() and italic() using a string, my map comes out as desired: plottitle <- expression(paste('Example map with ',…
mcjudd
  • 1,520
  • 2
  • 18
  • 33
10
votes
1 answer

Keeping trailing zeroes with plotmath

I'm using annotate() to overlay text on one of my ggplot2 plots. I'm using the option parse=T because I need to use the Greek letter rho. I'd like the text to say = -0.50, but the trailing zero gets clipped and I get -0.5 instead. Here's an…
9
votes
3 answers

How to fix degree symbol not showing correctly in R on Linux/Fedora 31

Any map I make with: ggplot() + geom_sf() produces the expected map, but does not show the degree sign correctly, as appears from the following picture. The answer given in this answer on SO - degree symbol incorrect in map axis labels - does…
giocomai
  • 3,043
  • 21
  • 24
9
votes
1 answer

Is paste a special argument in plotmath expressions?

When supplying a plotmath expression to a plot title I thought that paste worked just like paste, but now I am not sure. Is it a special argument to plotmath functions? In plotmath paste() behaves like paste0() and paste0 is quoted directly, whilst…
Simon O'Hanlon
  • 58,647
  • 14
  • 142
  • 184
8
votes
2 answers

R / ggplot2: Evaluate object inside expression

Example code: rsq <- round(cor(mtcars$disp, mtcars$mpg)^2, 2) # rsq = 0.72 ggplot(mtcars, aes(x = disp, y = mpg)) + geom_point() + geom_smooth(method = lm, aes(color = "Linear")) + scale_color_discrete(labels = expression(paste("R"^2, " = ",…
Jemus42
  • 629
  • 9
  • 24
8
votes
2 answers

Use sub-/superscript and special characters in legend texts of R plots

I generate a plot for multiple datasets. Each of the datasets should get it's own legend, which might contain greek letters, plotmath symbols or sub and superscrition. I'd like to generate the legend-texts in a loop. Bquote works fine, if there is…
R_User
  • 10,682
  • 25
  • 79
  • 120
7
votes
2 answers

Italic letters in generated axis tick labels

I have an issue creating axis tick labels that combine italic letters and input of variables. Simply said, I want to call variables and insert text such as n = 1 below each label. Here's an example with everything but the italic…
R. Rämö
  • 157
  • 5
7
votes
3 answers

degree symbol incorrect in map axis labels

If I create maps using geom_sf, the axis labels have the wrong symbol for degrees. I get degree symbols that are vertically centred in the text, rather than raised like superscipts. For example, library(sf) …
dww
  • 30,425
  • 5
  • 68
  • 111
7
votes
1 answer

How to make a hyphen, not minus sign, when using expression() to label in R?

I'm using expression() in my plot's x-axis label to create a square-root symbol over my measure's name to indicate that the data has been transformed using square-root transformation. However, my measure's name ("CES-D") has a hyphen in it. When I…
LC-datascientist
  • 1,960
  • 1
  • 18
  • 32
7
votes
1 answer

Add a bold female symbol to ggplot2 using annotate

I'm trying to use the female symbol, ♀ in my plot. It's pretty faint (well, it looks faint on my actual graph), so I was hoping to make it bold face. df <- data.frame(x = c(0, 1), y = c(0, 1)) ggplot(df, aes(x, y)) + geom_point() + theme_bw() + …
Nova
  • 5,423
  • 2
  • 42
  • 62
1
2
3
11 12