Line break in expression()?

You can easily use line breaks in regular paste, but this is plotmath paste (actually a different function also with no ‘sep’ argument) and the (long) ?plotmath page specifically tells you it cannot be done. So what’s the work-around? Using the plotmath function atop is one simple option: expression(atop(“Histogram of “*hat(mu), Bootstrap~samples*’,’~Allianz)) This will break … Read more

Use a variable within a plotmath expression

Use bquote(). Here is an example with dummy data: set.seed(1) DF <- data.frame(A = rnorm(100), B = rnorm(100)) mod <- lm(B ~ A, data = DF) R2Val<-signif(summary(mod)$r.squared[1], 2) The parts of the expression wrapped in .() get evaluated in the environment, i.e. the value of R2Val is substituted. plot(B ~ A, data = DF) text(1.5, … Read more

Adding greek character to axis title

If you’re using plotmath{grDevices}, the main help page (plotmath) contains an example of what you appear to want: xlab = expression(paste(“Phase Angle “, phi)) or for your case, I guess: ylab = expression(paste(“Diameter of aperture ( “, mu, ” )”)) Does this work for you?

Displaying a greater than or equal sign

An alternative to using expressions is Unicode characters, in this case Unicode Character ‘GREATER-THAN OR EQUAL TO’ (U+2265). Copying @mnel’s example .d <- data.frame(a = letters[1:6], y = 1:6) ggplot(.d, aes(x=a,y=y)) + geom_point() + scale_x_discrete(labels = c(letters[1:5], “\u2265 80”)) Unicode is a good alternative if you have trouble remembering the complicated expression syntax or if … Read more

How to change facet labels?

Here is a solution that avoids editing your data: Say your plot is facetted by the group part of your dataframe, which has levels control, test1, test2, then create a list named by those values: hospital_names <- list( ‘Hospital#1’=”Some Hospital”, ‘Hospital#2’=”Another Hospital”, ‘Hospital#3’=”Hospital Number 3″, ‘Hospital#4’=”The Other Hospital” ) Then create a ‘labeller’ function, and … Read more