楼主: verbatim
2506 8

[问答] how to add title and legend to the each page generated by for loop [推广有奖]

  • 1关注
  • 3粉丝

已卖:25份资源

博士生

5%

还不是VIP/贵宾

-

威望
0
论坛币
513 个
通用积分
2.0505
学术水平
0 点
热心指数
2 点
信用等级
0 点
经验
3404 点
帖子
139
精华
0
在线时间
143 小时
注册时间
2006-12-1
最后登录
2020-1-30

楼主
verbatim 发表于 2012-3-7 05:50:22 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
Dear All:

I have a 2 by 2 plots per page (4 plots/page) for total 12 pages (48 IDs) generated by the below example codes. How do I specify a title at the top center of each page and add a legend in the middle center of each page. I know mtext can add title and legend can add legend, but my problem is how to add them to each page (12 pages) not each plot (48 plots, 4 plots/page).

par(mfrow=c(2,2),mar=c(5,5,4,4))

for (i in unique(tak700$ID)){
j=tak700$ID==i

plot(tak700$TIME[j], tak700$DV[j], type='n', xlim=c(0,max(tak700$TIME[j])), ylim=c(0,max(tak700$DV[j],tak700$IPRE[j],tak700$PRED[j])),xlab='Time(hr)', ylab='Plasma Concentration(ng/ml)',cex=0.8)

lines(tak700$TIME[j], tak700$DV[j], type='b', col=2, pch=1, lwd=2, lty=4, cex=0.9)
}

But how and where to add the below example commands to generate title and legend per page for total 12 pages?

legend(80,10,col=6,lty=c(1,4),c('Predicted median','Predicted 95% PI'),lwd = 2,cex=1.1,bty='n')

mtext(outer=T, 'Phase II at steady state', side=3, line=-2,cex=1.2,col=2)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:generated generate Legend Title egen legend generated title

沙发
qoiqpwqr 发表于 2012-3-7 06:17:59
def.par <- par(no.readonly = TRUE)
x <- matrix(c(1,0,2,0,5,0,3,0,4), nrow = 3, byrow = T)
layout(x, c(3, 1, 3), c(3, 1, 3), TRUE)
oldMar1 <- par(oma = c(0, 0, 3, 0), mar = c(2.2, 1.5, 2, 0))
hist(rnorm(1000), col = 1)
hist(rnorm(1000), col = 2)
hist(rnorm(1000), col = 3)
hist(rnorm(1000), col = 4)
mtext("All histograms", outer = TRUE, cex = 1.5)
oldMar2 <- par(mar = c(0, 0, 0, 0))
plot.new()
legend('center', legend = 1:4, lwd = 3, col = 1:4)
par(def.par)
已有 2 人评分学术水平 热心指数 信用等级 收起 理由
UNC + 1 + 1 + 1 热心帮助其他会员
aspenroad + 1 + 1 + 1 热心帮助其他会员

总评分: 学术水平 + 2  热心指数 + 2  信用等级 + 2   查看全部评分

藤椅
qoiqpwqr 发表于 2012-3-7 06:19:05
Untitled.png
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
aspenroad + 1 + 1 + 1 观点有启发

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

板凳
tmdxyz 发表于 2012-3-7 08:55:57
版主一出手,就知有木有!

报纸
verbatim 发表于 2012-3-7 09:25:49
Thanks but this is not what I want. basically, I need add title and legend for 12 pages, each page has four plots from for loop, and each page need has title and legend. you only generate one page, and it is easy to add title and legend on only one page containing four plots.

地板
qoiqpwqr 发表于 2012-3-7 09:55:51
verbatim 发表于 2012-3-7 09:25
Thanks but this is not what I want. basically, I need add title and legend for 12 pages, each page h ...
add a counter i. If i can be divided by four, add the title and legend.

7
verbatim 发表于 2012-3-7 10:06:54
it doesn't work.

for (i in 1:12){
mtext()
lengend()
}

8
楚韵荆风 学生认证  发表于 2012-3-7 12:36:21
哈哈,版主就是厉害!~~
共享是一种彼此的快乐

9
aspenroad 发表于 2012-3-8 01:47:31
verbatim 发表于 2012-3-7 10:06
it doesn't work.

for (i in 1:12){
你没有判断是否画了四个图,如果是,就加标题和legend

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 23:40