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
303
votes
23 answers

How to change facet labels?

I have used the following ggplot command: ggplot(survey, aes(x = age)) + stat_bin(aes(n = nrow(h3), y = ..count.. / n), binwidth = 10) + scale_y_continuous(formatter = "percent", breaks = c(0, 0.1, 0.2)) + facet_grid(hospital ~ .) +…
wishihadabettername
  • 14,231
  • 21
  • 68
  • 85
67
votes
6 answers

Adding greek character to axis title

I want to add a greek character to the y-axis of my barplot in R. The problem is that I need this character to be integrated in the title. I want to write: Diameter of aperture ("mu"m) in the axis label. With ylab=expression() I can write the…
Rita
  • 673
  • 1
  • 5
  • 4
52
votes
4 answers

Displaying a greater than or equal sign

I have a plot which is generated thus: ggplot(dt.2, aes(x=AgeGroup, y=Prevalence)) + geom_errorbar(aes(ymin=lower, ymax=upper), colour="black", width=.2) + geom_point(size=2, colour="Red") I control the x axis labels like…
Robert Long
  • 5,722
  • 5
  • 29
  • 50
49
votes
2 answers

Line break in expression()?

I have the following histogram in R: hist( alpha, cex.main=2, cex.axis=1.2, cex.lab=1.2, main=expression( paste("Histogram of ", hat(mu), ", Bootstrap samples, Allianz") ) ) The title is too long, so I want a line break. According to this…
Jen Bohold
  • 1,038
  • 2
  • 10
  • 17
41
votes
2 answers

Special characters and superscripts on plot axis titles

I am trying to make a y-axis title with both a special character and a superscript. I am able to do this, but I want the closing parentheses not to be superscripted. And that's what I'm having a problem with. I think its just a placing of my…
Valerie S
  • 917
  • 2
  • 7
  • 17
30
votes
3 answers

Use a variable within a plotmath expression

I'm trying to place the results of a regression (i.e., R2) in a graph, but can't seem to figure out how to call a variable from within an expression (it pastes the variable name). Here is my code. R2Val <- signif(summary(sMod_pre90)$r.squared[1],…
sinclairjesse
  • 1,585
  • 4
  • 17
  • 29
29
votes
3 answers

Concatenate strings and expressions in a plot's title

How can I combine text and math expressions in a plot's title. If I use paste the expression is converted to character. For example I want something like this as a title $ARL_1$ curve for $S^2$ Thank you
Brani
  • 6,454
  • 15
  • 46
  • 49
22
votes
1 answer

R: How do I put two box plots next to each other, keeping same y-range for both?

Let's say I have two data sets, one with y-range [min0:max0] and the other with y-range [min1:max1]. How can put both box plots in one plot next to each other with a sane y-range [min(min0, min1):max(max0, max1)]? Here's what I tried: d0 <-…
htorque
  • 1,818
  • 4
  • 19
  • 22
17
votes
1 answer

How do I include italic text in geom_text_repel or geom_text labels for ggplot?

Is it possible to pass partially italicized text labels into ggplot? I have tried using the expression and italic commands (expression(paste(italic("some text")))), but these cannot be passed into a data frame because the result of the commands is…
Bob
  • 451
  • 1
  • 5
  • 12
17
votes
1 answer

How to underline text in a plot title or label?

I can't seem to figure out how to underline any part of a plot title. The best I could find was annotate("segment") done by hand, and I have created a toy plot to illustrate its method. df <- data.frame(x = 1:10, y = 1:10) rngx <- 0.5 *…
lawyeR
  • 7,488
  • 5
  • 33
  • 63
17
votes
4 answers

Mathematical expression in axis label

In R, I use expression(theta[l]) so that the label of my plot axis is that same as $\theta_l$ from LaTeX. For esthetic reasons, I'd rather like to display $\theta_\ell$. Can you help me? EDIT Before, I did plot(1:10, 1:10,…
Marco
  • 9,334
  • 7
  • 33
  • 51
16
votes
3 answers

How to have a new line in a `bquote` expression used with `text`?

I want to have a new line in my bquote envrionment, how can I do this? my code: test<-c(1,2,3,4,4.5,3.5,5.6) test2<-0.033111111 plot(test,c(1:length(test))) segments(4,0,4,23,col="red",lwd=2) text(5, 4.5, labels = bquote(Qua[0.99] ==…
Stat Tistician
  • 813
  • 5
  • 17
  • 45
14
votes
2 answers

multiple bquote items in legend of an R plot

Following works, (copy & paste into R) a=123 plot(1,1) legend('bottomleft',legend=bquote(theta == .(a))) I want to have multiple items in the legend. All with greek letters. As a simple example, if I repeat the item twice the code does not work…
Sang
  • 535
  • 5
  • 14
13
votes
1 answer

How to use several equal signs in text(x,y,expression(...))

is there a solution to use more than one equals signs in a expression (which are not within brackets)? I'm currently doing it with " = ". But thats not so nice, since == and " = " look different on the plot. Minimal sample: plot(0:5,0:5,…
user2451870
  • 133
  • 1
  • 4
13
votes
1 answer

Spacing in axis label when using expression(paste(...))

Consider the following example: plot(c(2,4,6)~c(1,2,3),xlab="x", ylab=expression(paste('flux (g ',CO[2]~m^{-2}~h^{-1},')'))) Obviously I want a full space between "g" and "CO", but for some reason I get a smaller (with some labels even zero) space…
Roland
  • 127,288
  • 10
  • 191
  • 288
1
2 3
11 12