[R] Partial italic in graph titles when looping

David Winsemius dwinsemius at comcast.net
Sun Feb 20 02:31:53 CET 2011


On Feb 19, 2011, at 7:41 PM, Josh B wrote:

> Dear all,
>
> I have a rather complicated problem. I am trying to loop through  
> making graphs,
> so that the graph-making process is fully automated. For each graph,  
> I'd like to
> make sure the corresponding title is formatted properly. The titles  
> will be a
> combination of a gene name and numerical position within the gene.  
> The gene name
> should be italic-bold, whereas the gene position should be just bold.
>
> Consider the following:
>
> x <- read.table(textConnection("gene position
> FLC 3312
> TFL1 687
> GA1 1127"), header = TRUE, as.is = TRUE)
> closeAllConnections()
>
> Now this, below, is essentially how I am automating the graph-making  
> (imagine
> these graphs contain some sort of real data):
>
> par(mfrow = c(3,1))
> for (i in 1:nrow(x)){
>    plot(z <- sort(rnorm(47)), type = "s", main = "")
>    points(z, cex = .5, col = "dark red")
>    title(main = paste(x[i,1], " p", x[i,2], sep = ""))
>    }

bquote is your friend (at least if one wants to use expressions rather  
than text):

for (i in 1:nrow(x)){
     plot(z <- sort(rnorm(47)), type = "s", main = "")
     points(z, cex = .5, col = "dark red")
     title(main = bquote(italic(.(x[i,1])*" p"*.(x[i,2]))))
     }

-- 
David.

>
> The graphs produced by this method are almost perfect, except that  
> the gene
> names are not italicized (they SHOULD be).
>
>
> So, once again, the big question is: how would I italicize the gene  
> names but
> NOT the gene positions, when looping through to make these graphs  
> and graph
> titles? If I WASN'T looping to make my graph titles, I could write:
>
> title(main = expression(paste(bolditalic("FLC"), bold("p3312"), sep  
> = " ")))
>
> ...but I can't do that, because I'm looping (or can I?)
>
> Thanks in advance for your help!
>
> -----------------------------------
> Josh Banta, Ph.D
> Center for Genomics and Systems Biology
> New York University
> 100 Washington Square East
> New York, NY 10003
> Tel: (212) 998-8465
> http://plantevolutionaryecology.org
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list