[R] reading graph metadata text from a file

Alexy Khrabrov deliverable at gmail.com
Tue Nov 20 16:05:55 CET 2007


I've tried tetxplot() but it fills the whole frame.  I could either  
use mfrow but it would devote unnecessarily large space to the text.   
In fact I want it in a corner of my current plot, not occupied by the  
curves.  Here's what I ended up with -- it works, but I have to  
manually move top text down as it's cut off by the upper boundary of  
the graph.  Any better/shorter/nicer ways?

First I fetch the dimensions of the current plot:

max.xy <- function() {
	p <- par()
	x.max <- p$usr[2]
	y.max <- p$usr[4]
	xy.coords(x=x.max, y=y.max)
}

Then, after plotting, I say

plot(...)

xy.max <- max.xy()

# top-right -- need to move a bit down or letters are cut off on top:
text(xy.max$x,xy.max$y*0.99,story$text,adj=c(1,1),col="blue")

# bottom-right -- no cut-off, a small nice gap comes free:
# story.text is story$text with some more appended details
text(xy.max$x, 0, story.text,adj=c(1,0),col="blue")

As for the original question -- I ended up creating, in each data  
directory, a file story.r, looking like this:

-----
# R titles, labels, and story text for the plot
# when I assigned color="blue" right in data.frame, it became an  
integer level!
story <- data.frame(title="",x="",y="",text="",color="")
story$title <- "graph title"
story$x <- "x units"
story$y <- "y units"
story$text <- "story text -- this data has come  long way.  Once upon  
a time there was R..."
    # we can separate colors of title, labels, and text like
    # title.color, x.color, y.color, text.color
story$color <- "dark blue"
-----

First I create a data.frame and then assign to its components one by  
one for readability.  When I tried to assign color right in data.frame 
(..., color="blue"), it became integer levels!  So I had to move it  
out along with others.  What's the logic here?

Cheers,
Alexy

On Nov 20, 2007, at 1:39 AM, Bert Gunter wrote:

> ... But is I understand correctly,this is certainly straightforward  
> without
> textplot,too...
>
> e.g.
> mylegend <- "Some text...\n Some more text"
> mytitle <- "This is a title"
> plot(0:1,0:1, main = mytitle)
> legend(.2,.2,leg=mylegend, bty="n")
>
> Naturally, this could all be "functionized" and the various text  
> arguments
> passed as arguments to the function (see ?plot.default or its  
> code); or they
> could be components of a list, or ...
>
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- 
> project.org] On
> Behalf Of Greg Snow
> Sent: Monday, November 19, 2007 2:18 PM
> To: Alexy Khrabrov; r-help at r-project.org
> Subject: Re: [R] reading graph metadata text from a file
>
> You may want to use the textplot function from the gplots package  
> rather
> than the legend.
>
> -- 
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> greg.snow at intermountainmail.org
> (801) 408-8111
>
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org
>> [mailto:r-help-bounces at r-project.org] On Behalf Of Alexy Khrabrov
>> Sent: Monday, November 19, 2007 1:17 PM
>> To: r-help at r-project.org
>> Subject: [R] reading graph metadata text from a file
>>
>> I'd like to produce graphs with titles, axis labels, and
>> legend as parameters read from a separate text file.
>> Moreover, I'd like to use the legend for a short summary of
>> the data -- not necessarily for describing the line colors
>> per se.  How do we do this?
>>
>> Cheers,
>> Alexy
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list