Suppose I've specified that the xlab for a plot is expression(bold(species~(italic(N1)))) In other words, I want the axis label to be bold, italic 'species (N1)' Now, I want the title for the plot to be have this label embedded in the title. Say, 'This is the plot for Species (N1)'. For a variety of reasons, I've set this up so that the xlab is a global parameter (basically, because the labels are set in a function which when called, generates various plots): x_label <<- expression(bold(species~(italic(N1)))) So, in the title, I've tried title(main=paste("This is the plot for ",x_label,"nullcline", sep=" ")); but what this does is generate something like 'This is the plot for bold(species~(italic(N1)))' In other words, it pastes the text of the expression into the title, but not what the expression 'evaluates' to. Is there any way around this? Thanks in advance... [[alternative HTML version deleted]]
> On Jan 11, 2016, at 7:59 AM, Evan Cooch <evan.cooch at gmail.com> wrote: > > Suppose I've specified that the xlab for a plot is > > expression(bold(species~(italic(N1)))) > > In other words, I want the axis label to be bold, italic 'species (N1)' > > Now, I want the title for the plot to be have this label embedded in the > title. > > Say, 'This is the plot for Species (N1)'. > > For a variety of reasons, I've set this up so that the xlab is a global > parameter (basically, because the labels are set in a function which > when called, generates various plots): > > x_label <<- expression(bold(species~(italic(N1))))> > So, in the title, I've tried > > title(main=paste("This is the plot for ",x_label,"nullcline", sep=" ")); > > but what this does is generate something like > > 'This is the plot for bold(species~(italic(N1)))' > > In other words, it pastes the text of the expression into the title, but > not what the expression 'evaluates' to. > > Is there any way around this?You instead need the `bquote` function. The `paste` function will only confuse things. In this particular instance it is embedding the literal as.character result of 'x_label'-value in a character object rather than in an expression-object. Since you have not offered a full example it remains unclear whether you want the words: "species" or "N1" rather than the values of those names.> > Thanks in advance... > > > [[alternative HTML version deleted]]This is a plain text mailing list.> > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius Alameda, CA, USA
David -- On 1/11/2016 1:01 PM, David Winsemius wrote:> >> On Jan 11, 2016, at 7:59 AM, Evan Cooch <evan.cooch at gmail.com> wrote: >> >> Suppose I've specified that the xlab for a plot is >> >> expression(bold(species~(italic(N1)))) >> >> In other words, I want the axis label to be bold, italic 'species (N1)' >> >> Now, I want the title for the plot to be have this label embedded in the >> title. >> >> Say, 'This is the plot for Species (N1)'. >> >> For a variety of reasons, I've set this up so that the xlab is a global >> parameter (basically, because the labels are set in a function which >> when called, generates various plots): >> >> x_label <<- expression(bold(species~(italic(N1)))) > >> >> So, in the title, I've tried >> >> title(main=paste("This is the plot for ",x_label,"nullcline", sep=" ")); >> >> but what this does is generate something like >> >> 'This is the plot for bold(species~(italic(N1)))' >> >> In other words, it pastes the text of the expression into the title, but >> not what the expression 'evaluates' to. >> >> Is there any way around this? > > You instead need the `bquote` function. The `paste` function will only confuse things. In this particular instance it is embedding the literal as.character result of 'x_label'-value in a character object rather than in an expression-object. Since you have not offered a full example it remains unclear whether you want the words: "species" or "N1" rather than the values of those names. >Thanks. I had wondered if bquote was the solution, but wasn't sure. Have followed your suggestion, but for the moment, am having problems getting it to work. I haven't figured out how to get bquote to actually evaulate the expression.> >> >> Thanks in advance... >> >> >> [[alternative HTML version deleted]] > > This is a plain text mailing list. >>Indeed -- forgot to flip the switch on my email client, which defaults to sending both plain text and HTML email.>> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius > Alameda, CA, USA > >
I tend to use bquote, as in x_label <- bquote(bold(species) ~ (italic(N1))) plot(1:10,main=bquote("This is the expression for" ~ .(x_label) * "!")) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jan 11, 2016 at 7:59 AM, Evan Cooch <evan.cooch at gmail.com> wrote:> Suppose I've specified that the xlab for a plot is > > expression(bold(species~(italic(N1)))) > > In other words, I want the axis label to be bold, italic 'species (N1)' > > Now, I want the title for the plot to be have this label embedded in the > title. > > Say, 'This is the plot for Species (N1)'. > > For a variety of reasons, I've set this up so that the xlab is a global > parameter (basically, because the labels are set in a function which > when called, generates various plots): > > x_label <<- expression(bold(species~(italic(N1)))) > > So, in the title, I've tried > > title(main=paste("This is the plot for ",x_label,"nullcline", sep=" ")); > > but what this does is generate something like > > 'This is the plot for bold(species~(italic(N1)))' > > In other words, it pastes the text of the expression into the title, but > not what the expression 'evaluates' to. > > Is there any way around this? > > Thanks in advance... > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
On 1/11/2016 2:08 PM, William Dunlap wrote:> I tend to use bquote, as in > > x_label <- bquote(bold(species) ~ (italic(N1))) > plot(1:10,main=bquote("This is the expression for" ~ .(x_label) * "!")) > > >Thanks -- I thought I'd tried something very close to this in my various attempts, but it would seem, not close enough. I'll give your suggestion a try. It isn't a critical feature/need on my end (since I can live without elements of the title being bold, or italic), but I'm always happier knowing what to do if I *need* do - in future.