Is there a way to modify the axis labels on trace plots? I ran the first regression model in the examples of the run.jags() help file. Then I tried this command:
which gives me the label "1 2 3" on all three panels of the plot. I also tried supplying a list to the ylab argument instead of a character vector, and I tried using the panel argument instead of ylab with no luck (but reading the lattice documentation brought back fond memories). Am I missing something simple?
Thanks,
Ed
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Good question - to which the answer is 'kind of'. Or more precisely: 'no - but there is an ugly hack'.
Before the ylab variable is evaluated (in a function deep inside runjags) the 'col' and 'varname' variables are assigned to the calling environment. So if we can map the current variable name to the desired variable name, then you can use a switch statement wrapped inside an expression statement (we need to force lazy evaluation because 'varname' is not known at the time of the call to plot()). So if we are running the regression model example with variables m, c and precision then we can define a labeller function as:
This works ... but it is not pretty. To be honest, I'm not even sure if the expression(varname) trick is documented anywhere - if not it probably should be.
Cheers,
Matt
ps. As an interesting aside, this doesn't work when the return from swtich is numeric - i.e. compare:
Is there a way to modify the axis labels on trace plots? I ran the first regression model in the examples of the run.jags() help file. Then I tried this command:
plot(results, "trace", trace.options=list(ylab=c("1","2","3")))
which gives me the label "1 2 3" on all three panels of the plot. I also tried supplying a list to the ylab argument instead of a character vector, and I tried using the panel argument instead of ylab with no luck (but reading the lattice documentation brought back fond memories). Am I missing something simple?
Thanks,
Ed
Hi Ed
Good question - to which the answer is 'kind of'. Or more precisely: 'no - but there is an ugly hack'.
Before the ylab variable is evaluated (in a function deep inside runjags) the 'col' and 'varname' variables are assigned to the calling environment. So if we can map the current variable name to the desired variable name, then you can use a switch statement wrapped inside an expression statement (we need to force lazy evaluation because 'varname' is not known at the time of the call to plot()). So if we are running the regression model example with variables m, c and precision then we can define a labeller function as:
And then pass a call involving this label_fun as the argument to ylab:
This works ... but it is not pretty. To be honest, I'm not even sure if the expression(varname) trick is documented anywhere - if not it probably should be.
Cheers,
Matt
ps. As an interesting aside, this doesn't work when the return from swtich is numeric - i.e. compare:
with:
I have no idea why this is ... if anybody can work this out I would greatfully accept answers on a postcard!
Thanks, that's exactly what I was looking for, and exactly what I would have never figured out by myself!
Ed