如何更改以下代码:
这是问题Plotting axis labels with Greek symbols from a vector和Subscripts in plots in R的混合。
# vector of symbols to go in graphs
symbol_list <- c("alpha", "beta", "gamma");
set.seed(1234);
count <- 1;
for (symbol in symbol_list){
# random data
x <- runif(10, 0,1);
y <- runif(10, 0,1);
png(paste0("test",count,".png"));
# make graph with different symbol in x label at each iteration
plot(x,y, xlab=parse(text = paste("log *",symbol)));
dev.off();
count <- count+1;
}
答案 0 :(得分:1)
这应该这样做。如果循环索引i
,则不需要计数器。
symbol_list = c("alpha", "beta", "gamma")
for (i in 1:length(symbol_list)){
# random data
x <- runif(10, 0,1);
y <- runif(10, 0,1);
png(paste0("test",i,".png"));
# make graph with different symbol in x label at each iteration
plot(x,y, xlab=parse(text=paste("log~",symbol_list[i],"[R]")))
dev.off();
}