【发布时间】:2021-11-25 09:04:27
【问题描述】:
你能帮我在 R 表达式中为绘图赋值吗
#define function which takes n to genrate random numbers and asscoiated histogram
plot_sim <- function(n_sim = NULL){
rand_var <- runif(n_sim)
hist(rand_var, freq = F, main = expression(paste('Histogram of rand_var ',bar(X)[n = n_sim])))
}
#for possible n run function through a for loop
possible_n = c(100,2000,400)
for (i in 1:length(possible_n)){
plot_sim(possible_n[i])
}
【问题讨论】:
-
还有,
main = parse(text = sprintf('Histogram~of~rand_var~bar(X)[%s]', n_sim))
标签: r function loops plot expression