使用矢量和下标中的希腊符号绘制轴标签

时间:2014-09-16 18:48:46

标签: r loops plot symbols subscript

如何更改以下代码:

  • 符号后面的下标(例如,LaTeX中的$ \ alpha_R $,$ \ beta_R $,$ \ gamma_R $)
  • “log”和符号之间的空格(尝试按照建议设置“〜”,但不起作用)

这是问题Plotting axis labels with Greek symbols from a vectorSubscripts 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;
}

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();
}