[R] Plot title with numeric variables
RMan54
RMan54 at cox.net
Wed Nov 15 03:02:20 CET 2006
This works for the original posted question:
n<-5
title <- bquote(bold(paste("Figure ", .(n), ": Plot ", C[max], " versus
CrCl")))
plot(1, main=title)
However, my problem is that I want to define the text before the value of n
is known.
The idea is that the title is defined ahead, passed to a function that makes
many plots, and n is incremented for each plot.
One way to accomplish this would be to have the constant part of the title
defined ahead:
fff <- bquote(paste("Plot ", C[max], " versus CrCl"))
Unfortunanely, I need to use bquote() or expression() in order to get the
subscript correctly (subscript in the wordprocessing sense = text placed a
little bit lower than normal).
And then add to this the changing part at the time the plot is made (when
the value of n is correct).
The changing part is:
ccc <- bquote(paste("Figure ", .(n), ":"))
Unfortunatley, I need to use bquote() or substitute() here to replace n with
it's numeric value. This can actually be done simplier: paste("Figure", n,
":")
I just don't know how to concatenate both fff and ccc to create the title.
I am wondering whether it is possible to construct variables or strings that
contain the text plus the special charaters for subscript (square brackets)
and the code for replacement of n by its numeric value, and then evaluate
the combination as part of a substitute() function.
As a try that does not work:
fff <- expression(paste("Plot ",C[max]," versus CrCl")) # Need
expression() for subscript text
n<-5
ccc <- bquote(paste("Figure ", .(n), ":"))
# Need bquote() for replacement of n; can be done with substitute() also, or
simple: paste("Figure", n, ":")
title <- paste(fff, ccc) ##### Does not work; produces strange results in
plot title #####
plot(1, main=title)
LARGER PEROBLEM:
My larger problem is to construct a number of plots in sets with the same
title per set (fixed part per set) but with the title number incremented
with 1 starting with 1 (variable part). I wanted to define the fixed part of
the title in the main loop but have the figure counter rolling in a function
just before each plot is constructed at which time the figure number is
known.
Very ackward, but this works as the main loop:
numSetsOfPlots <- 1:2
numPlotsPerSet <- 1:3
n <- 0
for (setNo in numSetsOfPlots) {
for (plotInSetNo in numPlotsPerSet) {
n <- n + 1
if (setNo == 1) myTitle <- bquote(paste("Figure ", .(n), ": ",
C[max]))
if (setNo == 2) myTitle <- bquote(paste("Figure ", .(n), ": ", AUC))
plot(1, main=myTitle) # Will be a call to a more complex plot function
readline('Press Enter to proceed...')
}
}
At this point, I can NOT separate a Figure counter from the fixed part of
the title. Both have to be combined in the same main loop. The need for the
subscript for which a PlotMath function is needed causes this problem.
--------------------------
Rene Braeckman, PhD (RMan54)
Irvine, CA
RMan54 wrote:
>
> I am trying to create a plot title in R with substitution by a numeric
> variable (Figure number N) within the text which is bold and has a
> subcripted part as well. Here is what I have:
>
> title <- expression(bold(paste("Figure ", N, ": Plot ", C[max], " versus
> CrCL")))
>
> plot(1, main="") # Simple plot for testing
> N <- 5
> mtext(title, line=3, font=2, cex=1.25)
>
> I have the bold part and the subscripted text worked out but how do I
> replace the text "N" in the title by its numeric value (5 in this
> example)? I tried all kinds of stuff with substitute, etc. but can't
> figure it out.
>
> The last 3 lines are actually from a function with title as argument. N is
> internal to the function and changes.
>
> Any help is much appreciated. Thanks.
> Rene
>
>
--
View this message in context: http://www.nabble.com/Plot-title-with-numeric-variables-tf2631678.html#a7350682
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list