如何在图中显示参数

时间:2018-03-18 02:30:46

标签: r plot statistics

我想显示alpha = 2,beta = 2。 即参数

beta_plot <- function(a, b, ...) {
  x <- seq(0, 1, by = 0.02)
  y <- dbeta(x, shape1 = a, shape2 = b)
  plot(x, y, main = expression(paste(alpha, " = ", a,"  ", beta, " = ", b)),  xlab = NA, ylab = NA, ...)
}
beta_plot(2, 2)

但 它显示

enter image description here

我该怎么办?

1 个答案:

答案 0 :(得分:2)

我们可以使用bquote

beta_plot <- function(a, b, ...) {
 x <- seq(0, 1, by = 0.02)
  y <- dbeta(x, shape1 = a, shape2 = b)
  plot(x, y, main = bquote(alpha~" = "~.(a)~" "~beta~" = "~.(b)  ),
              xlab = NA, ylab = NA, ...)
 }

beta_plot(2, 2)

enter image description here