[R] hist densities

2008-03-21 Thread Luke Spadavecchia
Hi there,

I was wondering why

x-rnorm(n=5000,mean=1.5,sd=0.25)
h-hist(x)
sum(h$density)

[1] 10

I thought the integral of the histogram should be one? These seems  
strange to me, or am I being silly...

Regards Luke Spadavecchia

PS. I'm using R 2.5.1 on Mac OSX

__
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] question on image() function?

2007-11-08 Thread Luke Spadavecchia
You could try using levelplot from the lattice package:

library(lattice)
levelplot(mcpvalue~x+y)

failing that, interpolate them to a grid using akima or fields then  
display with image

L

On 8 Nov 2007, at 18:13, Duncan Murdoch wrote:

 On 11/8/2007 11:51 AM, zhijie zhang wrote:
 Dear friends,
   My dataset is like the following:
  xy  mcpvalue
 0.4603578 0.6247629   1.001
 0.4603715 0.62477881.001
 0.4603852 0.6247948   1.001
 0.4110561 0.5664841   0.995
  The x and y variables are unsorted.
  I use the function image(x,y,mcpvalue) to generate a plot, but  
 the error
 is that increasing 'x' and 'y' values are expected. So i use
image(x=seq(min(x),max(x)), y=seq(min(y),max(y)),z=as.matrix
 (result$mcpvalue))
 to do it again, but there is still an error dimensions of z are not
 length(x)(-1) times length(y)(-1).
   Anybody can show me how to use the image() correctly with the  
 original x/y
 unsorted?

 You can't, it doesn't know how to handle that kind of data.

 image() is designed to display a matrix of values.  The x and y values
 tell it where to put the rows and columns of the matrix.

 You have a set of points.  You need to fit a surface to them, evaluate
 the surface on a grid, and pass that to image().

 There are many ways to do that; the akima package has the interp()
 function for instance.

 Duncan Murdoch

 __
 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-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] Polygon shading line colors

2007-10-30 Thread Luke Spadavecchia
Hi there,

I'm having trouble working out how to change the colors of polygon  
shading lines. If I plot a polygon with

polygon(poly,density=30,borders=gray(0.5))

I get gray borders but black shading lines; I have tried adding  
col=gray(0.5), bg=gray(0.5) and fg=gray(0.5), but no luck.
How can I change the colors of the shading? The help file doesn't  
seem to detail this, so any suggestions would be greatly appreciated.

Many thanks

Luke Spadavecchia

__
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] x11 window queston

2007-10-29 Thread Luke Spadavecchia
Hi all,

Sorry for reposting, but I think my last request was a little confusing.

I am trying to keep my x windows open after I exit the R session, so  
when I have produced a series of plots from R I would like to retain  
the graphics as x windows after exiting with q(). This would be  
particularly useful for batch mode execution of R scripts; at the  
moment when I run scripts with R CMD BATCH myscript.R my graphics  
flash up in the x window momentarily, but disappear as R exits  
(providing x11 is running and I use Sys.setenv(DISPLAY=:0.0)  
before opening x with x11()). Is it possible to retain these (as it  
is in GNUPLOT using the persist option), both in interactive and  
batch mode? I am able to keep the plot open for examination by adding  
a long serial loop to the end of the script, but this is not a  
particularly good solution.

I am able to save the contents of the x windows as pdf, bmp etc with  
dev.print(), but I would rather retain the graphics in an open x  
window, so I could keep the plots on screen after a system call to R  
from other programs.

Many thanks

Luke Spadavecchia

PS. I am running R-2.4.1 on Mac OS X (intel processor), and Windows  
XP with the same results on both systems

__
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] X11 graphics windows under CMD BATCH

2007-10-28 Thread Luke Spadavecchia
Hi Dirk,

Thanks for your useful advice, although I am not sure I fully  
understand your response.

I am able to open x11 windows from R CMD BATCH both in windows  
XP,MAC  OS X and Linux (on various machines I use), providing the  
relevant Sys.setenv() commands are in the script I call prior to  
plotting commands. My problem is that the X11 windows only persist as  
long as the script is running, and disappear when R exits - which is  
very rapid for most plots (it is only when the script imports a  
shapefile using maptools or something like that that the window is  
open long enough to really examine the plot).

Is there a way when running R (from batch mode or otherwise) of  
'saving' X11 windows, and keeping them open after the R session is  
complete? I don't really want to write the graphics to file, because  
the repeated calls from the Fortran code would overwrite each other,  
and the idea is to do rapid appraisal of the simulated annealing  
schedule, to check that mixing/cooling are progressing in an  
efficient and  useful manner. Would using cairo (which I can't seem  
to get to work at the moment) allow me to do this? I'm not sure it's  
an x11 problem, but rather something to do with the way that R and  
X11 communicate?

Many thanks

Luke Spadavecchia

__
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] X11 graphics windows under CMD BATCH

2007-10-24 Thread Luke Spadavecchia
Hi there,

I am trying to plot some output from a  FORTRAN (ifort) program using  
R (2.5.1) under batch mode. In the FORTRAN code, I call R in batch  
mode to execute a script called fig1.R using something like

PROGRAM test
USE IFPORT
IMPLICIT NONE

DO
!Some function which makes an output file called 
~/fortran_output.txt
CALL myfunc()

!System call to R plotting routine
CALL SYSTEM (open -a x11)
CALL SYSTEM (R CMD BATCH ~/fig1.R)
END DO

END PROGRAM test

The system call goes through fine, and R fires up and processes the  
contents of fig1.R which are something like:

Sys.setenv(DISPLAY=:0.0)
Data-read.table(~/fortran_output.txt)
x11(width=12)
plot(Data$var1,Data$var2)

My problem is that I want the x11 window which the plot appears in to  
persist after R exits; currently the figure flashes up momentarily,  
then disappears as R exits. One option is to try and stall the exit  
of R, by sticking a big loop at the end of the code, but this means  
my FORTRAN program is hanging about waiting for the loop to finish,  
and my plot still disappears. Is there any equivalent to -persist in  
GNUPLOT to allow the x11 window to stay open after R exits, so I can  
examine the results while the program continues?

To put all this in context, I want to examine the results of a  
simulated annealing process at each temperature reduction stage of  
the annealing schedule. I am not doing the annealing in R for reasons  
of speed: I only want to use R as a graphics engine.

Many thanks

Luke Spadavecchia

__
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.