Skip to content

Multiple graph sheets

8 messages · Paul, David A, Chunlou Yung, Spencer Graves +3 more

#
In Splus the code

test.lm <- lm(y ~ x, data = test.data)
plot(test.lm)

generates a graphics window that contains
multiple graph sheets that one may choose
from via the "page" tabs at the bottom of
the window.

Is there a way to do this sort of thing in
R?  As another example, I have some repeated
measures data with continuous outcomes and 
have been working with the nlme library in Splus.
When I use the commands


library(nlme)
data.grouped <- groupedData(y ~ time | x, 
                            data = test.data)
plot(data.grouped, layout = c(5,3,11))


generates 11 separate graph sheets that can
be toggled between.  In R, the same commands
generate a sequence of graph sheets, but only
the last one is "saved" in the graphics 
window.  Is there a way around this?


Much thanks,

David Paul, Ph.D.
Battelle Memorial Institute
614.424.3176
#
It seems all R-to-CGI libraries (all two of them, which I'm aware) run only
on Unix/Linux  (but I use Windows) and create temporary files to pass R
commands.

So, I wrote a short Apache-based Perl CGI script to execute R commands on
browser without needing temporary files--just for fun, babyish, nothing
robust, slow but works. (The rationale? I prefer distributing results via
the intranet on browser, rather than sending huge spreadsheets around, for
which the sysadmin bitterly complained causing the email server to grow
unduly large.)

Here it is, in case anyone interested (more like a "sample answer" than a
product, for sure):

#-----------------------------File Name:
simpleR.pl---------------------------
#! /usr/local/bin/perl -w
use Apache::Request () ;
use strict ;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# You only need to modify this:
my $Rpath = "C:\\R\\rw\\bin\\" ;		# path to rterm.exe
# The rest will hopefully run itself.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# to execute R cmd: R($Rpath, $R_cmd)
sub R {
	my $Rpath = shift ;
	my $Rcmd = $Rpath . "rterm --vanilla --quiet --slave" ;
	my $Rscript = shift ;
	$Rscript =~ s/(\r|;\r)/ ;/gm ; $Rscript =~ s/<-/=/gm ;	# \r or <- break
"echo"
	return `echo $Rscript | $Rcmd` ;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
my $r = shift ;					# Apache stuff
my $q = Apache::Request->new($r) ;		# Apache Query obj
my $command = $q->param('command') ;
my $result = $command ? R($Rpath, $command) : "You didn't input any
command." ;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
print "Content-type: text/html\n\n";
print <<"EOF";
<html><body>
	<form method="get" action="./simpleR.pl">
		Please enter your R command:<br>
		<textarea rows="4" name="command" cols="60">$command</textarea><br>
		<input type="submit" value="Submit">
	</form><br>
	<textarea rows="10" name="result" cols="80">$result</textarea>
</body></html>
EOF
exit;
#
On Wed, 18 Jun 2003, Paul, David A wrote:

            
Well, you can only do that in S-PLUS *for Windows* (it is one of several
options for a graphsheet() device). In R for Windows there is a windows()  
device where you can turn on history recording and move between plots with
the page keys.  (This is in the README!)

One again, R is not S-PLUS, and if you want features of S-PLUS, why not 
use it?  Especially if they are user-level convenience features.
4 days later
#
Hello all,

I am looking for books to help me gain a firmer grasp on the S/R
programming language ,  programing / data structures etc. it seems that
for this purpose two books are typically recommended: 

Programming with Data: A Guide to the S Language, John M. Chambers and
S Programming by Venables & Ripley.

- The Chambers book is published 1998. is it a bit dated at this point.
- is the Venables and Ripley's book a good source on the design and
manipulation of data structures in R (it seems mostly focused on R
extensions).
- are there any other books, possibly published more recently, that you
could recommend.


I also have a couple of particular programming questions:

-coming from a C++/java programming background I found that I often end
up in R with lists of objects (each constructed, in turn, as a list, say
list(x=x,y=y,z=z)). often, these individual objects have recursive
'attributes' so a matrix representation of this set of objects is not an
option. although a data.frame might be. I typically need to access
certain attributes of these objects for plotting or analysis etc.
however, I have not been able to come up with a clean way to do this?
e.g.

object.list = list(o1=list(x=1,y=2,z=3), o2=list(x=11,y=22,z=33))

what I would like to do is say get a vector of x values for the objects
in object.list, but something like
object.list[[1:length(object.list)]]$x, for example, returns NULL.

is there a better way to set up such an object list data structure that
will allow me to do this?

- what is the correct way to -remove- a component from a list. this
seems to do the trick: list[[1]] = NULL, however, you'd think this
should simply attach a NULL object at the first component position?  

many thanks for any help
#
I can help with the second of the three questions I see your email:

 > object.list = list(o1=list(x=1,y=2,z=3), o2=list(x=11,y=22,z=33))
 > sapply(object.list, function(x)x$x)
o1 o2
  1 11

See for example Venables and Ripley (2002) Modern Applied Statistics 
with S, 4th ed. (Springer, pp. 33-34).

hth.  spencer graves
Murad Nayal wrote:
#
Murad Nayal wrote:

            
Although it was published in 1998, I hardly find it outdated.  Still a 
good reference, but as far as I know, not everything is implemented in R.
Modern Applied Statistics in S (4th ed.) by Venables & Ripley is not so 
much about the language itself but is always a good reference.
You can use sapply:

sapply(object.list, "[[", "x")
-roger
#
On Mon, 23 Jun 2003, Murad Nayal wrote:

            
This is in the FAQ, section 3.3.3, and is an S/R difference that catches
people quite often.  It's related to the difference between [] and [[]].

Generally you will find that it is better to program by generating whole 
lists with lapply() or to copy lists retaining what you want (which does 
not copy the components, in general, and so is cheap).


As for your comments on books: `S Programming' does discuss the design of
classes (both informal and formal), the main data sructures in R. As
others have said, the Green Book (Chambers, 1998) is by not means out of
date, except in the sense that the precise langage it describes has never
been available: it is not a description of any version of S-PLUS nor R.

Generally, though, you need to make sure you have at your fingertips the
resources which come with R: the various manuals (including R-lang) and
the on-line help.  For example, I have just spend several days documenting
in the help pages exactly how subscripting of data frames works (and
correcting dozens of anomalies and bugs).
#
thanks you all for the replies, it's been very helpful.

regards
Prof Brian Ripley wrote: