Reputation: 609
I'm making a boxplot which has the variance shown on the plot, as follows:
boxplot(avgs, xlab="Technique",ylab="Accuracy of Prediction", cex = 1.5)
num <- round(var(data$gblup),3)
label <- expression(paste(sigma,"² = ",num))
text(x= 1, y= 0.4, labels= label)
However, I'm instead seeing this:
I'm trying to place the contents of the double num into the label, without much luck. Thanks in advance for any help in doing this.
Upvotes: 0
Views: 155
Reputation: 887148
We can construct the expression with bquote
num <- round(var(iris$Sepal.Length),3)
label <- bquote(sigma^2 == .(num))
boxplot(iris$Sepal.Length)
text(1, 6, labels = label)
-output
Upvotes: 1
Reputation: 160447
Here's one way, I'll use sprintf
to ensure three digits, and bquote
to handle the expression and exponent.
boxplot(mtcars$disp)
num <- sprintf("%0.03f", var(mtcars$disp))
text(1, 220, bquote(sigma^2 * " = " * .(num)))
(I like akrun's use of ==
, which produces a slightly longer equals sign and looks more intuitive in the code.)
Upvotes: 1