[R] Overlay of two graphs of different axes

2010-09-12 Thread Uwe Dippel
Though I have read quite a bit, and tried quite a bit, I have yet to 
find a nice way to overlay 2 or more curves in the same plot, with 
different ranges.

Here is simplified sample code to demonstrate the question:

 plot(2*(seq(1,5)), type=l, axes=FALSE)
 curve(2*(seq(1,5)), type=b, add=TRUE)
Error in curve(2 * (seq(1, 5)), type = b, add = TRUE) :
  'expr' must be a function or an expression containing 'x'
 axis(2)
 curve(x^2, 1, 5, type=b, add=TRUE)
 axis(4)

Firstly, as an aside, I am not clear why 'curve' has a different syntax 
compared to 'plot'. As a still beginner, I'd for one would be happy to 
add curves to a plot; curves of just different parameters. Though, I 
guess, there must be a good reason?


Mostly, however, I wonder how to plot a number of curves into an 
original plot, that re-defines the min/max from the most recent curve.


In the example that I constructed, axis(2) does exactly the expected thing.
What I want to do next, though, with the least effort, is to add another 
function in a manner that the added function is scaled, not according to 
the first function (plot), but to fit into the plotting area. (The 
example above overshoots the range).
Plus, how can I subsequently add the axis suitable to the most recent 
function? That is, how can I render axis(4) to displaying the scale for 
the second graph, created with 'curve'?


Thanks in advance,

Uwe

__
R-help@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] Consistent behaviour of for-loop

2010-04-15 Thread Uwe Dippel
First my excuses if I keep bugging everyone in this list, but I am a 
newbie, and tend to find some behaviour that looks unexpected to me; and 
I would really appreciate to be pointed to some location that allows me 
to understand more about this software. Here is my next question:

 par(mfrow=c(1,1))
 qqnorm(rnorm(20))
 qqmath(rnorm(20))
 par(mfrow=c(3,4))
 for(i in 1:12)qqnorm(rnorm(20))
Until here everything works as expected, and the last line prints 12 
samples of qqnorm. However,

 for(i in 1:12)qqmath(rnorm(20))
is doing nothing at all.

As I wrote, I'd really appreciate the understand where this behaviour 
comes from.


Thanks in advance,

Uwe

__
R-help@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.


Re: [R] Consistent behaviour of for-loop

2010-04-15 Thread Uwe Dippel

Peter Ehlers wrote:

  par(mfrow=c(1,1))
  qqnorm(rnorm(20))
  qqmath(rnorm(20))
  par(mfrow=c(3,4))
  for(i in 1:12)qqnorm(rnorm(20))
Until here everything works as expected, and the last line prints 12
samples of qqnorm. However,
  for(i in 1:12)qqmath(rnorm(20))
is doing nothing at all.



You should always tell us what contributed packages you are using.
Here, the qqmath function is from pkg:lattice.
Now check FAQ 7.22.
  

Thanks, Peter!
(And to the offline-reply as well!)
The question is not completely answered in FAQ 7.22, though:
 par(mfrow=c(3,4))
 for(i in 1:12)print(qqmath(rnorm(20)))
prints 12 after another; not in (3,4)

Why, and how to print 12 samples on a single sheet?

Uwe

__
R-help@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.


Re: [R] Consistent behaviour of for-loop

2010-04-15 Thread Uwe Dippel

Peter Ehlers wrote:

You are mixing 'traditional' graphics (par(...)) and
'lattice' graphics.
That won't work. In lattice, you use the 'layout' argument to
select the number of columns/rows. This is easiest if you set
up a conditioning variable:

  cond - gl(12, 20, labels = letters[1:12])
  x - rnorm(12*20)
  qqmath(~x | cond, layout = c(4, 3))

Note that layout = c(columns, rows), not c(rows, columns).

Since you're new to R, let me also recommend very strongly
that you learn to use the str() function (not needed for
this problem, but undoubtedly indispensible in your further
adventures in R-land).
  

Nice example, and good recommendation!

(It is difficult to satisfy me:)
How can one know/see, what is traditional graphics, and what is lattice 
graphics? Or is it try-and-fail-and-use-the-alternative?


Thanks,

Uwe

__
R-help@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.


Re: [R] Consistent behaviour of for-loop [Solved]

2010-04-15 Thread Uwe Dippel

Greg Snow wrote:
The first thing to do is look at the help page for the function: ?qqnorm and ?qqmath, the package where these functions are defined is at the top of the page, if that package is graphics then it is a base graphics function, if the package is grid, lattice, or ggplot2 then it is grid based graphics. 


SOLVED,
and thanks for the answer.

Is your goal really to produce a whole set of normal qq plots from random data? 
 If so, you may be interested in the vis.test function in the TeachingDemos 
package (and associated functions).  One way to run this will mix together a 
qqplot of your data along with data generated from a normal distribution with 
the same mean and var so you can visually compare the plot of your data to 
plots of normal (and then lets you try to choose which is the real data).
  


SOLVED, again. This is what I had in mind: demonstrating a bunch of 
normal qq-plots, by visually placing them side by side.

I'll try the TeachingDemos next.

Uwe

__
R-help@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] TeachingDemos install bumps out with 'Out of memory!'

2010-04-15 Thread Uwe Dippel

The same thing that happened to my 'maptools'
(http://permalink.gmane.org/gmane.comp.lang.r.general/177404)
also hits me here: It eats all memory until the system dies.
Alas, in this case, no Ubuntu package.
Since I installed some tens of packages with the same method in the 
meantime, I guess something must be wrong with the install.packages; at 
least on Ubuntu9.10, amd64.


(And I am not out of memory, really:
Mem:   3347584k total,   812872k used,  2534712k free,12648k buffers
Swap:  4305380k total,   618464k used,  3686916k free,   272476k cached)

Uwe

__
R-help@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] classes and functions for qqnorm and stem

2010-04-14 Thread Uwe Dippel
Referring to Using R for Data Analysis and Graphics by J H Maindonald, 
and available from the R site, I found the example on p.30 non-working:

 stem(qqnorm(possum$hdlngth))
Error in stem(qqnorm(possum$hdlngth)) : 'x' must be numeric
Since qqnorm(possum$hdlngth) plots, and
 class(possum$hdlngth)
[1] numeric
, the problem must be here:
 class(qqnorm(possum$hdlngth))
[1] list
Does 'stem' require numerical input? The help says so.
But how to render it numeric?:
 class(as.numeric(qqnorm(possum$hdlngth)))
Error: (list) object cannot be coerced to type 'double'

Can someone please enlighten me about what goes wrong/has changed here?

Uwe

__
R-help@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] Question about simple.median.test

2010-04-08 Thread Uwe Dippel
I am studying Using R for Introductory Statistics and find it in 
general very useful. At present, I am stumbling over the function 
simple.median.test.


 x
[1] 12.8  3.5  2.9  9.4  8.7  0.7  0.2  2.8  1.9  2.8  3.1 15.8
 simple.median.test (x,median=5)
[1] 0.3876953
 simple.median.test (x,median=10)
[1] 0.03857422
until here it is identical to the document. Then I played for myself:
 simple.median.test (x,median=3)
[1] 1.225586
The result is 1 here. Is my interpretation wrong, that the result is a 
probability?


Uwe

__
R-help@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.


Re: [R] Frequencies from a matrix - spider from frequencies

2010-03-21 Thread Uwe Dippel

Jim Lemon wrote:

Yes, I realized that I had forgotten to require(plotrix) after I sent
the message. From your example, you might also want to look at the 
diamondplot function, also in plotrix.
  


Jim,

thanks for the hint to diamondplot. It is much closer natively to what I 
wanted to do, and simple to use. Hats off!: Just entering the data frame 
produces a quick print.

However, it fails to make sense w.r.t. units and values here.
I use the example data and code given in ?diamondplot:
data(mtcars)
 
mysubset-mtcars[substr(dimnames(mtcars)[[1]],1,1)==M,c(mpg,hp,wt,disp)]

 diamondplot(mysubset)
and get a plot (I think I can't attach it here?), with, e.g.
hp and disp crossing the Maserati radial axis at 17, wt at 15 and mpg at 10.
The actual data row, though, is
 mpg  hpwt  disp
Maserati Bora 15.0 335 3.570 301.0

Looking closer, the plot seems to arbitrarily scale all values (columns) 
to a(n arbitrary?) maximum of '17'.
And when I print my data (submitted earlier), the same happens: all 
responses are scaled to 17 as the highest in each category. From that 
point of view, diamondplot is not that useful. How can I force it not to 
scale arbitrarily, but print the actual numbers?


Uwe

__
R-help@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] Frequencies from a matrix - spider from frequencies

2010-03-15 Thread Uwe Dippel
First of all, I really like R! Still being a newbie, I find things (the 
difficult ones) to be very simple.
Alas, some 'simple' things still escape me. (Maybe the tutorials are 
often too much focused on the 'difficult' items??)


Here comes my 'problem', over which I have sweated for the last 2 hours:
My data are of a matrix 10x31, Likert Scale (1-5). 10 questions, 31 
respondents. Now, I want to display the frequencies per question. I have 
not found any better (any more simple) than

for (in in 1.10) print (table(learn[,i]))
And then, still, the scale is printed 10 times as well. I am sure, there 
is a better function, but I didn't find one.
Actually, I would want the scale once, atop ('names'), and then the 
10(questions) * 5 (length.of.scale) thereunder, like

1 2 3 4 5
1   3 4 2 1 2
2   5 9 2 1 4
3   4 4 6 1 3


And, now somewhat less of the ordinary, a spider/radar showing the 
number of responses for each question (circular axis, 10), with the 
frequencies as radial axes. That is, 5 polygons showing the frequencies 
of the responses per each question.


Any help is appreciated, and my excuses for asking a simple question,

Uwe

__
R-help@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] Packages gnumeric and xlsReadWrite

2010-03-15 Thread Uwe Dippel

Both packages are listed on the website, but neither installs here:

gnumeric:
...
Cannot find xml2-config
ERROR: configuration failed for package ‘XML’
* Removing ‘/usr/local/lib/R/site-library/XML’
* Installing *source* package ‘gnumeric’ ...
** R
** preparing package for lazy loading
Warning in library(pkg, character.only = TRUE, logical.return = TRUE, 
lib.loc = lib.loc) :

there is no package called 'XML'
Error : package 'XML' could not be loaded
ERROR: lazy loading failed for package ‘gnumeric’
* Removing ‘/usr/local/lib/R/site-library/gnumeric’
(Ubuntu 9.10)

xlsReadWrite:
 install.packages(xlsReadWrite)
Warning in install.packages(xlsReadWrite) :
argument 'lib' is missing: using '/usr/local/lib/R/site-library'
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
package ‘xlsReadWrite’ is not available

__
R-help@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.


Re: [R] Frequencies from a matrix - spider from frequencies

2010-03-15 Thread Uwe Dippel

Jim Lemon wrote:

Hi Uwe,
Here's one way to get your spider plot:

ld1-matrix(sample(1:5,310,TRUE),nrow=31)
ld2-apply(ld1,2,table)
radial.plot(ld2,line.col=2:6,rp.type=p,
  radial.pos=seq(0,9*pi/5,by=pi/5),
  labels=paste(Q,1:10,sep=),start=pi/2,
  clockwise=TRUE,main=Frequency of response by question)
par(xpd=TRUE)
legend(8,12,1:5,col=2:6,lty=1)
par(xpd=FALSE)

Quite a bit of overlap on the polygons, however.
  


Thanks, Jim,

this one works (with your random data)! (In case anyone reads and wants 
this as well, package plotrix provides radial.plot.)
The overlap is normal, because it's random data. When the respondents 
have a less random streak of answering (and they do), this plot will 
show some continuity throughout the questions; and identify those 
questions clearly, which fall outside of this continuity.

This is why I prefer to use it here.

Uwe

__
R-help@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] SimpleR and UsingR

2010-02-06 Thread Uwe Dippel
Having found the online version of SimpleR, I wanted to to download the 
respective data:
The data sets for these notes are available from the CSI math 
department (http://www.math.csi.cuny.edu/Statistics/R/simpleR)

and must be installed prior to this.

There it says:
The simpleR package is now inside the UsingR package available from 
CRAN. In the Windows GUI, this may be installed from a menubar item. 
Otherwise, the following command  install.packages(UsingR) will work ...

I did, and got a package of
Content type 'application/x-gzip' length 502288 bytes (490 Kb) 
downloaded and installed. Alas, the command given in the notes:

 library(Simple)
Error in library(Simple) : there is no package called 'Simple'
seems not to work. But when I try
 installed.packages()
UsingR shows up.

Can anyone please enlighten me, what is going on here? Thanks,

Uwe

__
R-help@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] Compilation error with maptools

2010-01-29 Thread Uwe Dippel
I had downloaded and installed a number of packages, successfully, when 
I ran into some problem with maptools: It would eat up CPU and most of 
all memory.
I rebooted, and tried again, only running the terminal after the reboot; 
with the same result:


 sp2WB text html latex example
sp2tmap text html latex example
spCbind-methods text html latex example
Out of memory!
ERROR: building help failed for package ‘maptools’
* Removing ‘/usr/local/lib/R/site-library/maptools’

The downloaded packages are in
‘/tmp/RtmpG9Vj1D/downloaded_packages’
Warning message:
In install.packages(maptools) :
installation of package 'maptools' had non-zero exit status

I did install it then, using
sudo apt-get install r-cran-maptools
without problem; it also works.

(I am on Ubuntu Karmic; sp and Hmisc, however, install without any problem.)

My RAM is 4GB, my swap likewise.

Uwe


Uwe

__
R-help@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] Explanation w.r.t. rbind, please!

2010-01-29 Thread Uwe Dippel

This is what I tried:

 num.vec - c(12.34,56.78,90.12,34.56)
 names(num.vec)-c(first,second,third,fourth)
 num.vec
first second  third fourth
12.34  56.78  90.12  34.56
 seq-(1:4)  
 num.mat-rbind(num.vec,seq)
 num.mat   
   first second third fourth

num.vec 12.34  56.78 90.12  34.56
seq  1.00   2.00  3.00   4.00
 num.vec [3:4]
third fourth 
90.12  34.56


(until here I'm fine)

 num.mat [seq]
[1] 12.34  1.00 56.78  2.00
 num.mat [num.vec]
[1] NA NA NA NA   
 num.vec [seq]

first second  third fourth
12.34  56.78  90.12  34.56
 num.mat [num.vec]
[1] NA NA NA NA
 num.mat [-seq]  
[1] 90.12  3.00 34.56  4.00


(and here I'm lost!)

How could I display a row, instead of always seemingly falling back to 
columns?


Uwe

__
R-help@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.



Re: [R] Explanation w.r.t. rbind, please!

2010-01-29 Thread Uwe Dippel

Meyners,Michael,LAUSANNE,AppliedMathematics wrote:

What you (probably) want here is
num.mat [seq,]

  

  num.mat [num.vec]
[1] NA NA NA NA   



num.mat[num.vec,]

and so on. You have to use tell R that you want the ROW (that's why the
comma is needed) defined by the NAME seq or num.vec (that's why you
need ) .


Thanks, I had been exactly there before, and it didn't work neither. Now 
it works. I do understand the need for the rows *now*.


Uwe

__
R-help@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.