简体   繁体   English

向循环图R添加标题

[英]Adding titles to loop graph R

Im trying to loop a lot of graphs in R. The code im using looks like this: 我试图在R中循环很多图。我使用的代码如下所示:

#--------------------------------------------------------------------
#### Read data & Converting factors ####
dat <- read.table("Complete RING.txt", header =TRUE)  
str(dat)
dat$Vial <- as.factor(dat$Vial)
dat$Line <- as.factor(dat$Line)
dat$Fly <- as.factor(dat$Fly)  
dat$Temp <- as.factor(dat$Temp)
str(dat)


meltet <- melt(dat, id=c("Concentration","Sex","Line","Vial", "Fly", "Temp", "Vial_nr"))
meltet1 <- subset(meltet, Line=="20")
meltet1$variable <- as.factor(meltet1$variable)

AllConcentrations <- levels(unique(meltet1$Concentration))
for (i in AllConcentrations) {
meltet.i <- meltet1[meltet1$Concentration ==i,]
quartz()
print(dotplot(value~variable|Temp, group=Sex, data = meltet.i ,xlab="Time", ylab="Fly position", main=paste("Line 20 concentraion", AllConcentrations[i]))) }

The concentrations im using are denoted A, B, C, D, E, X and Y - how do i add a title to the plot that changes with the plots, i have tried to use the main=" " function but then i get the same name in each graph. im使用的浓度分别表示为A,B,C,D,E,X和Y-我如何为随图而变化的图添加标题,我尝试使用main =“”函数,但随后我得到了每个图中的名称相同。 The title i get now is: Line 20 concentration NA in each graph 我现在得到的标题是:每张图中的第20行浓度NA

EDIT: updated the code 编辑:更新了代码

I believe that the AllConcentrations vector which you are looping through is a of class "character." 我相信您要遍历的AllConcentrations向量是“字符”类的。 If you want to use this in your title, use main=AllConcentrations[i] . 如果要在标题中使用它,请使用main=AllConcentrations[i] You can also make this fancier with the paste function: main=paste("Graph of", AllConcentrations[i]) . 您还可以通过以下粘贴功能使这个幻想: main=paste("Graph of", AllConcentrations[i])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM