1

How do I change the code below to have:

  • a subscript after the symbol (e.g. it would be $\alpha_R$, $\beta_R$, $\gamma_R$ in LaTeX)
  • a space between the "log" and the symbol (tried putting a "~" as suggested, but it didn't work)

This is a mixture of the questions Plotting axis labels with Greek symbols from a vector and 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;
}
Community
  • 1
  • 1
Catalina
  • 171
  • 9

1 Answers1

1

This should do it. If you loop through an index i, you don't need a counter.

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();
} 
Vlo
  • 3,168
  • 13
  • 27
  • Hmm... you wouldn't know how to put an absolute value in there too, would you? (log|alpha_R|) Sorry I can't vote up, my reputation is too low, else I would! – Catalina Sep 16 '14 at 20:40
  • `plot(x,y, xlab=parse(text=paste("log~abs(",symbol_list[i],"[R]",")")))` – Vlo Sep 16 '14 at 21:02
  • Yay!! It works perfectly. You totally made my day -- now I don't have to make 8 different plotting functions for each parameter name! – Catalina Sep 16 '14 at 21:11