使用R中的循环的情节的不同标题 [英] Different titles for plots using loop in R
本文介绍了使用R中的循环的情节的不同标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图循环绘制图.但是,如何在每个情节上放置不同的标题?在此示例中,我要为8个密度图使用不同的名称,例如beta [Treatment],beta [Time Dummy]等.谢谢!
I am trying to make plots in a loop. But how do I put different titles on each plot? In this example, I want different names for my 8 density plots, such as beta[Treatment], beta[Time Dummy], etc. Thanks!
par(mfrow=c(4,2)
for (i in 2:8) {
plot(density(beta[,i]))
title(main=substitute(paste('Density of ', beta[Treatment]))))
}
推荐答案
tvec <- c("Treatment", "Time Dummy")
par(mfrow=c(2,1))
for(i in 1:2){
plot(density(beta[,i]),
main=substitute(paste('Density of ', beta[a]), list(a=tvec[i])))
}
或者实际上,如果您的下标名称是 beta
列的名称:
Or actually if the name of your subscripts is the name of the columns of beta
:
par(mfrow=c(4,2))
for(i in 2:8){
plot(density(beta[,i]),
main=substitute(paste('Density of ', beta[a]), list(a=colnames(beta)[i])))
}
这篇关于使用R中的循环的情节的不同标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文