Re: [R] Artifacts in filled.contour+pdf

2010-10-25 Thread baptiste auguie
Hi,

As an alternative, maybe you could use lattice::panel.levelplot.raster
which I think doesn't have this problem in pdf viewers.

HTH,

baptiste


On 26 October 2010 02:30, David Winsemius dwinsem...@comcast.net wrote:

 On Oct 25, 2010, at 6:50 AM, Mario Valle wrote:

 Dear all,
 I'm using R 2.12.0 on Windows 7 (32bits)
 I created a filled contour from the attached data using the following
 code:

 load('bug.RData')
 pdf('bug.pdf', width=14, height=7)
 filled.contour(o4$x, o4$y, o4$z, color=rainbow, xlim=c(4,18),
 ylim=c(0,35), zlim=c(14,36))
 dev.off()

 If you look (I used acrobat reader 9.4) at the attached bug.pdf, you see
 an incomplete grid of gray lines.

 From the pdf help page:
 Note
 If you see problems with PDF output, do remember that the problem is much
 more likely to be in your viewer than in R. Try another viewer if possible.
 Symptoms for which the viewer has been at fault are apparent grids on image
 plots (turn off graphics anti-aliasing in your viewer if you) and missing or
 incorrect glyphs in text (viewers silently doing font substitution).

 Unfortunately the default viewers on most Linux and Mac OS X systems have
 these problems, and no obvious way to turn off graphics anti-aliasing. 

 Are they there when printed?

 On a Mac I can make the lines in that pdf graphic appear and disappear in
 different places on my screen by changing the Page Display settings for
 Resolution in Acrobat Reader, and viewing in other applications like
 GraphicConverter I see even more lines tha I do in Acrobat Reader.

 --

 David.

 This artifact is not present if the output is PNG (attached, obtained in
 the above code using png('bug.png', width=800, height=400) instead of
 pdf()).
 Seems like a off-by-one bug. Is it a known bug? Is there any workaround? I
 tried lattice::contourplot but it does not support NA.
 Thanks for your help!
                                               mario

 --
 Ing. Mario Valle
 Data Analysis and Visualization Group            |
 http://www.cscs.ch/~mvalle
 Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91)
 610.82.60
 v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91)
 610.82.82


 bug.pdfbug.png__
 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-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] ggplot2: how to label lines?

2010-10-26 Thread baptiste auguie
Hi,

Have a look at the directlabels package; it does just that for lattice
and ggplot2.

HTH,

baptiste

On 26 October 2010 08:02, Jeffrey Spies jsp...@virginia.edu wrote:
 Hi, all,

 Let's say I have some time series data--10 subjects measured 20
 times--that I plot as follows:

 library(ggplot2)
 dat - data.frame(subject=as.factor(rep(1:10, each=20)),
 time=rep(1:20, 10), measure=as.vector(replicate(10, rnorm(20,
 mean=runif(1, 0, 15), sd=runif(1, 1, 3)
 p - qplot(time, measure, data=dat, colour=subject, geom=line)
 p

 What would be the preferred way to add a single label to every line?
 For instance, labels might be most readable at the beginning, end, or
 peak (max value) of every line.  I could do:

 p + geom_text(aes(label=subject))

 But this gets messy when the labels are longer than single digits;
 instead, I want a single label per line. I suppose a dataset could be
 put together composed of single points and labels and then layered
 atop p, but perhaps there is a more direct method.

 Any help would be greatly appreciated,

 Jeff.

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


Re: [R] extracting named vector from dataframe

2010-10-31 Thread baptiste auguie
Hi,

I think you want ?unlist

d = data.frame(x=1, y=2, z=3)
v = unlist(d)
is(v)
[1] numeric vector

HTH,

baptiste

On 31 October 2010 16:54, James Hirschorn james.hirsch...@hotmail.com wrote:
 Suppose df is a dataframe with one named row of numeric observations. I want
 to coerce df into a named vector.



 as.vector does not work as I expected: as.vector(df) returns the original
 dataframe, while as.vector(df,mode=numeric) returns an unnamed vector of
 NAs.



 This works:



 v - as.numeric(as.matrix(df)); names(v) - names(df);



 I just wanted check if there was a better/more natural way of doing this?


        [[alternative HTML version deleted]]

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


Re: [R] Using R for Production - Discussion

2010-11-02 Thread baptiste auguie
Hi,

Regarding your '10 commandments' in Q3, you may find useful tips in
the R inferno by Pat Burns.

HTH,

baptiste

On 2 November 2010 05:04, Santosh Srinivas santosh.srini...@gmail.com wrote:
 Hello Group,

 This is an open-ended question.

 Quite fascinated by the things I can do and the control I have on my
 activities since I started using R.
 I basically have been using this for analytical related work off my desktop.
 My experience has been quite good and most issues where I need to
 investigate and solve are typical items more related to data errors, format
 corruption, etc... not necessarily R Related.

 Complementing this with Python gives enough firepower to do lots of
 production (analytical related activities) on the cloud (from my research I
 see that every innovative technology provider seems to support Python ...
 google, amazon, etc).

 Question on using R for Production activities:
 Q1) Does anyone have experience of using R-scripts etc ... for production
 related activities. E.g. serving off a computational/ analytical /
 simulation environment from a webportal with the analytical processing done
 in R.
 I've seen that most useful things for normal (not rocket science) business
 (80-20 rule) can be done just as well in R in comparison with tools like
 SAS, Matlab, etc.

 Q2) I haven't tried the processing routines for much larger data-sets
 assuming size is not a constraint nowadays.
 I know that I should try out ... but any forewarnings would help. Is it
 likely that something that works for my desktop dataset is quite as likely
 to work when scaled up to a cloud dataset?
 Assuming that I do the clearing out of unused objects, not running into
 infinite loops, etc?

 i.e. is there any problem with the fundamental architecture of R itself?
 (like press articles often say)


 Q3) There are big fans of the SAS, Matlab, Mathworks environments out there
  does anyone have a comparison of how R fares.
 From my experience R is quite neat and low level ... so overheads should be
 quite low.
 Most slowness comes due to lack of knowledge (see my code ... like using the
 wrong structures, functions, loops, etc.) rather than something wrong with
 the way R itself is.
 Perhaps there is no commercial focus to enhance performance related issues
 but my guess is that it is just matter of time till the community evolves
 the language to score higher on that too.
 And perhaps develops documentation to assist the challenge users with
 performance tips (the ten commandments types)

 Q4) You must have heard about the latest comment from James Goodnight of SAS
 ... We haven't noticed that a lot. Most of our companies need industrial
 strength software that has been tested, put through every possible scenario
 or failure to make sure everything works correctly.
 My gut is that random passionate geeks (playing part-time) do better
 testing than a military of professionals ... (but I've no empirical evidence
 here)

 I am not taking a side here (although I appreciate those who do!) .. but
 looking for an objective reasoning.

 Thanks,
 S

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


Re: [R] How do I order xyplot line points?

2010-11-07 Thread baptiste auguie
Hi,

try this,

xyplot(Time~Chromosome|factor(Elements),
   data = mtx[order(mtx$Chromosome), ], ... [snipped])


HTH,

baptiste





On 7 November 2010 13:17, Alex Reynolds reyno...@u.washington.edu wrote:
 I have the following xyplot figure:

  http://img577.imageshack.us/img577/686/filesizeresults1200.png

 The data are organized in a matrix file as follows:

  Type  Elements        Chromosome      Time
  bedGz 1200        chr1    14.240
  bedGz 1200        chr2    7.949
  bedGz 1200        chr3    5.103
  bedGz 1200        chr4    5.290
  bedGz 1200        chr5    5.161
  ...

 The x-axis labels in the Chromosome column are ordered lexicographically in 
 my figure ( chr1  chr10  chr11  ... ) — this is correct.

 However, the code I use to draw lines between points in the xyplot connects 
 points in numerical order ( chr1  chr2  ... ) — this is incorrect.

 The problem this causes is most evident in the line that is drawn for the 
 blue bedGz category.

 What I would like is that categorical points are joined by lines in 
 lexicographic order, to match ordering of labels on the x-axis.

 How do I modify the xyplot command so that the lines are joined in correct 
 order?

 Here is the code I am using to draw my xyplot:

 mtx - read.table(mtxf.in, as.is=F, sep=\t, quote='', header=T, 
 stringsAsFactors=T)
 attach(mtx)
 postscript(mtxf.ps,
           width = 12,
           height = 6,
           paper = 'special',
           horizontal = F)
 par(mar=c(0.0, 0.0, 0.0, 0.0))
 mtx.p - xyplot(Time~Chromosome|factor(Elements),
                mtx,
                type=o,
                groups=Type,
                col = c(
                  'red',
                  'green',
                  'red',
                  'green',
                  'blue'),
                auto.key=list(
                  lines=TRUE,
                  space=right),
                ylab=CPU Time (sec),
                xlab=Type,
                main=Extraction time for archive types)
 print(mtx.p)
 dev.off()

 Sorry if this is a dumb question. Thanks for your advice.

 Regards,
 Alex
 __
 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.


Re: [R] [lattice] densityplot label the peak.

2010-11-10 Thread baptiste auguie
Hi,

The easiest way might be the directlabels package from R-forge.
Otherwise, you could write your own panel function.

HTH,

baptiste


On 10 November 2010 23:01, Joon Yeong Kim joonyeen...@gmail.com wrote:
 Hi,

 I've been trying to find a way to label the the peak or mean of a
 densityplot for a while but haven't been successful. Does anyone know how to
 accomplish this?


 Thank you for your help in advance.


 Joon

        [[alternative HTML version deleted]]

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


Re: [R] rasterImage and coordinate conversion

2010-11-18 Thread baptiste auguie
Hi,

For curiosity's sake, below is another version with ggplot2 and Grid graphics,

library(pixmap)
logo - read.pnm(system.file(pictures/logo.ppm, package=pixmap)[1])

library(ggExtra) # r-forge, requires gridExtra
qplot(rnorm(100),rnorm(100)) +
  annotate(pixmap, x=-Inf, y=-Inf, picture=logo, vjust=0, hjust=0, raster=T)


baptiste


On 18 November 2010 20:47, Paul Murrell p...@stat.auckland.ac.nz wrote:
 Hi

 Rajarshi Guha wrote:

 Hi, I have a plot and I would like to overlay a PNG image over it. I'm
 using the rasterImage function to do this, but the problem I'm facing
 is working out the coordinates of the upper right corner of the final
 image in user coordinates.

 That is I can place the image so the lower left is located at the
 bottom of the y-axis and the left end of the x-axis. Since my image is
 say 100px x 100px, is there a way for me to convert a 100px length
 into the appropriate value in user coordinates, along the x-axis?

 Are you trying to draw the image at its native resolution?

 R should be able to scale the image using interpolation to whatever size you
 want, but if you really want to try for native resolution, this should get
 you close ...

 # Import a raster image
 library(pixmap)
 logo - read.pnm(system.file(pictures/logo.ppm, package=pixmap)[1])

 # Image size
 l...@size

 # A plot
 plot(rnorm(100), rnorm(100))

 # If you know the screen resolution, use that, otherwise
 # the device may be telling R something close to the truth
 dpi - (par(cra)/par(cin))[1]

 usr - par(usr)
 xl - usr[1]
 yb - usr[3]
 xr - xl + xinch(l...@size[2]/dpi)
 yt - yb + yinch(l...@size[1]/dpi)

 # Image at native resolution
 rasterImage(matrix(rgb(l...@red, l...@green, l...@blue),
                   nrow=l...@size[1]),
            xl, yb, xr, yt)


 Paul

 Thanks,



 --
 Dr Paul Murrell
 Department of Statistics
 The University of Auckland
 Private Bag 92019
 Auckland
 New Zealand
 64 9 3737599 x85392
 p...@stat.auckland.ac.nz
 http://www.stat.auckland.ac.nz/~paul/

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


Re: [R] how to draw manifold?

2010-11-21 Thread baptiste auguie
Hi,

I'm joining in with a question -- is it possible to vary the color of
the lines along z? The 'colors' argument doesn't seem to allow a
vector in this situation.

Thanks,

baptiste



On 21 November 2010 21:02, Carl Witthoft c...@witthoft.com wrote:
 Thanks, Dennis.   Here's an enhanced version:

  z - seq(-10, 10, 0.1)
  zm-cbind(z,z,z,z,z,z,z,z,z,z)

 ym-matrix(nr=201,nc=10)
 for (i in seq(1,201)) {
        for (j in seq(1,10)) ym[i,j]-j/10*sin(zm[i,1])}

 xm-matrix(nr=201,nc=10)
 for (i in seq(1,201)) {
        for (j in seq(1,10)) xm[i,j]-j/10*cos(zm[i,1])}


 scatterplot3d(as.vector(t(xm)), as.vector(t(ym)), as.vector(t(zm)), main =
 'Helix', pch = .,type='l')


 From there I can draw a few helical lines by modifying your original code
 (for different radii), and end up with a pretty decent mesh surface.

 Carl


 On 11/20/10 12:03 PM, Dennis Murphy wrote:

 Hi:

 Here's an example stolen out of the scatterplot3d package vignette (p. 9):

 library(scatterplot3d)
 z- seq(-10, 10, 0.01)
 x- cos(z)
 y- sin(z)
 scatterplot3d(x, y, z, highlight.3d = TRUE, col.axis = 'blue',
               col.grid = 'lightblue', main = 'Helix', pch = 20)

 HTH,
 Dennis

 On Sat, Nov 20, 2010 at 8:29 AM, Carl Witthoftc...@witthoft.com  wrote:

 Hi,
 I need some help either in how to configure variables for wireframe(), or
 some suggestions as to other graphics commands to use for plotting a 2-D
 manifold in 3-D space.

 Here is an example I tried (in the hopes that it would plot a helical
 line)
 :

 xsp-matrix(c(cos(seq(0,80)/5)),9,9)
 ysp-matrix(c(sin(seq(0,80)/5)),9,9)
 zsp-matrix(c((seq(0,80)/20)),9,9)
 wireframe(zsp~xsp*ysp)

 The resulting plot looks vaguely like a helix, but not right.  And if I
 change my variables' dimensions to c(3,27) it looks better, but if the
 dims are c(1,81), nothing gets plotted.

 So: is there a way to control which points are connected by lines in
 wireframe()?  Or is there a more appropriate way to provide a plotting
 program with sets of coordinates in 3-space?

 My primary goal is to be able to plot surfaces, not just a line as in my
 sample code.  For example, I might expand the data above to represent
 points
 on a 'ribbon' helix.

 Thanks for yr. help -- feel free to point me to help files for existing
 packages or plotting routines.

 Carl

 __
 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-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] Is it possible to make a matrix to start at row 0?

2010-11-22 Thread baptiste auguie
Apparently He who starts from 0 needn't be called unfortunate,

fortune('indexed')

baptiste

On 22 November 2010 20:59, Ben Bolker bbol...@gmail.com wrote:
 Bert Gunter gunter.berton at gene.com writes:


 Eh??? Why would you want to do that?? (R isn't C).

 So the simple answer is: you can't.

 The other answer is, well of course you sort of can via, e.g.

 for(i in 0:9)  {
    z - myMatrix[i+1,]
   ...
 }

 But as Josh said, I think this falls into the class of You are just
 asking for trouble, so don't do it.

 Cheers,
 Bert

  But if you still want to after all those warnings, you can ...
 see the Oarray package, where the first letter of the package
 name is a capital letter oh (O), not a zero (0).

  library(fortunes); fortune(Yoda)

  There ought also to be a clever fortune() expressing the sentiment
 that you may eventually find (weeks, months, or years later) that
 changing the way you solve your problem to go with R's flow would
 have been easier than implementing a solution that works around
 the flow (examples abound: -, zero-based arrays, eval(parse()),
 storing names  of variables as character vectors and using get()
 [FAQ 7.21], etc, etc, etc ...)

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


Re: [R] specifying colours in a ggplot2 piechart

2010-11-23 Thread baptiste auguie
fixing the various typos in your code, this works,

lat_plot() +
scale_fill_manual(value=mycolours)

HTH,

baptiste

On 23 November 2010 19:47, John Kane jrkrid...@yahoo.ca wrote:
 Someone was asking how to do a 16 category piechart in OpenOffice Calc and it 
 appears that it can not be done (which we, probably, should be happy about) 
 but I thought that I'd try it in ggplot2.

 It works but I then thought I'd like to make the colours more distinctive but 
 fro some reason I don't seem to be able to use manually assigned colours.

 Can anyone suggest where I'm going wrong?

 Thanks

 ===


 library(ggplot2)
 mypie - data.frame(xx = c(12,13,6,7,9,10,4, 3, 8, 6, 8, 4, 6,5,2,3),
 zz = letters[1:16])

 mycolours - c(a =  red, b = blue, c =  green, d = orange, e = red,
 f = blue, g = geen,   h = orange, i = red, j = blue,
 k = green, l = orange, m = red,  n = blue, o = green,
 p = orange )

  pie1 - ggplot(mypie, aes(x = factor(zz), fill = factor(zz))) + 
 geom_bar(width = 1)
  pie2 -  pie + coord_polar(theta = x) + scale_colour_brewer(Pastel1)
  pie2

  # try to get even nastier piechart with ugly colours to provide rast.

  pie3 - pie2 + scale_colour_manual(value=mycolours)
  pie

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


Re: [R] specifying colours in a ggplot2 piechart

2010-11-23 Thread baptiste auguie
Colour affects the lines and points in ggplot2, whilst fill is for
areas (polygons, etc.)

By the way, I can't type either -- I meant  last_plot().

baptiste


On 23 November 2010 20:18, John Kane jrkrid...@yahoo.ca wrote:
 Obviously I cannot type or spell.

 Your solution was great but do you have any idea why
  scale_colour_manual(value=mycolours)
 does not work.  More typos on my part or am I misunderstanding what  
 scale_colour_manual(value=mycolours) is supposed to do?

 Thanks


 --- On Tue, 11/23/10, baptiste auguie baptiste.aug...@googlemail.com wrote:

 From: baptiste auguie baptiste.aug...@googlemail.com
 Subject: Re: [R] specifying colours in a ggplot2 piechart
 To: John Kane jrkrid...@yahoo.ca
 Cc: r-h...@stat.math.ethz.ch
 Received: Tuesday, November 23, 2010, 2:02 PM
 fixing the various typos in your
 code, this works,

 lat_plot() +
 scale_fill_manual(value=mycolours)

 HTH,

 baptiste

 On 23 November 2010 19:47, John Kane jrkrid...@yahoo.ca
 wrote:
  Someone was asking how to do a 16 category piechart in
 OpenOffice Calc and it appears that it can not be done
 (which we, probably, should be happy about) but I thought
 that I'd try it in ggplot2.
 
  It works but I then thought I'd like to make the
 colours more distinctive but fro some reason I don't seem to
 be able to use manually assigned colours.
 
  Can anyone suggest where I'm going wrong?
 
  Thanks
 
 
 ===
 
 
  library(ggplot2)
  mypie - data.frame(xx = c(12,13,6,7,9,10,4, 3, 8,
 6, 8, 4, 6,5,2,3),
  zz = letters[1:16])
 
  mycolours - c(a =  red, b = blue, c =
  green, d = orange, e = red,
  f = blue, g = geen,   h = orange, i = red, j
 = blue,
  k = green, l = orange, m = red,  n = blue, o
 = green,
  p = orange )
 
   pie1 - ggplot(mypie, aes(x = factor(zz), fill =
 factor(zz))) + geom_bar(width = 1)
   pie2 -  pie + coord_polar(theta = x) +
 scale_colour_brewer(Pastel1)
   pie2
 
   # try to get even nastier piechart with ugly colours
 to provide rast.
 
   pie3 - pie2 +
 scale_colour_manual(value=mycolours)
   pie
 
  __
  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.


Re: [R] apply over list of data.frames

2010-11-24 Thread baptiste auguie
Hi,

Try this,

do.call(`+`, x) / length(x)

HTH,

baptiste

On 24 November 2010 20:37, Tim Howard tghow...@gw.dec.state.ny.us wrote:
 R users,
 This probably involves a simple incantation of one of the flavors of apply... 
 that I can't yet figure out. Consider a list of data frames. I'd like to 
 apply a function (mean) across the list and return a dataframe of the same 
 dimensions where each cell represents the mean of that cell across all 
 dataframes.

 # set up the list
 x - vector(list,2)
 names(x) - c(one,two)
 # add data to the list
 for(i in 1:2){
  y = i^2
  x[[i]] - 
 data.frame(a=c(y,2*y,3*y),b=c(y+1,y+2,y+3),c=c(2*y+1,2*y+2,2*y+3))
  }
 #show the list
 x
 $one
  a b c
 1 1 2 3
 2 2 3 4
 3 3 4 5

 $two
   a b  c
 1  4 5  9
 2  8 6 10
 3 12 7 11
 #the result should be
  a b c
 1 2.5 3.5 6
 2 5 4.5 7
 3 7.5 5.5 8

 Can anyone direct me down the right path?

 Thanks in advance
 Tim Howard




        [[alternative HTML version deleted]]

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


Re: [R] Comparing two functions

2010-11-28 Thread baptiste auguie
Hi,

Your function fails for a number of reasons. One of them is your
comparison (use browser() to see what is the value taken by f in your
function). Also, n, mean, min and max could not be extracted from ...
with your construction.

Here's my suggestion,

randomIra = function(f=runif, ...){
switch(f,
   rnorm = do.call(rnorm, c(sd=1, list(...))) ,
   runif = , # will use the next one, which is also the default
   runif(...))
}

randomIra(rnorm, n = 5, mean = 20)
randomIra(runif, n=5, min = 10, max = 25)
randomIra(, n=5, min = 10, max = 25) # default


HTH,

baptiste




On 28 November 2010 11:53, Ira Sharenow irasharenow...@yahoo.com wrote:
 Hi. I am new to R and facing a problem that I cannot solve.



 I am writing some basic functions. Then I would like to have a master 
 function that allows me to call one of the functions which I created, but I 
 cannot figure out how to do so.



 Below is an example. The functions rnormIra and runifIra both seem to work 
 fine. I do not get an error message when entering the definition of the 
 master function randomIra; however, it fails when I use it to call another 
 function.



 Can someone please help?



 Thanks.



 Ira



 rnormIra = function(n, mean) {
  return(rnorm(n,mean,1))
 }
 rnormIra(10,100) #works fine



 runifIra = function(n,min,max) {
  return(runif(n,min,max))
 }
 runifIra(5,20,30) #works fine



 randomIra = function(f, ...) {
  if(f == rnormIra) {
   return(rnormIra(n,mean))
  }
  else {
        return(runifIra(n,min,max))
  }
 } #no error messages



 randomIra(rnormIra, n = 5, mean = 20) #FAILS
 randomIra(runifIra, n = 5, min = 10, max = 25) #FAILS

 do.call(randomIra,list(rnormIra,5,20)) #FAILS


        [[alternative HTML version deleted]]

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


Re: [R] Bug 14340 - Symbols() plots with wrongly scaled y-axis

2010-07-17 Thread baptiste auguie
Hi,

try adding asp=1 in symbols() to set the aspect ratio of the plotting
region to 1.

HTH,

baptiste


On 17 July 2010 18:21,  nancy...@gmail.com wrote:
 Hello, I submitted this bug report to r-core and got a rejection saying I
 should post to r-help.
 This is my first time ever submitting a bug report, so forgive me if I'm
 using some wrong format.

 So, here's my bug report:

 Component:  Graphics
 OS:  Mac OS 10.5.8, X11 XQuartz 2.5.0
 Summary:
 In the symbols function of the graphics package, scaling of the y-axis is
 wrong, causing symbols that should be separate to overlap in the y-direction
 (x-direction is okay).

 Description:
 Attached is a plot that should be of circles of radius 5 spaced exactly with
 their centers 10 apart in both x and y directions, so that they should be
 packed with the circles touching edge-to-edge.  In the y-direction, somehow
 the
 plotting scale is wrong such that the circles overlap.  I've plotted
 horizontal
 and vertical lines at x=45,50,55, and y=45,50,55, as well as two squares
 with
 side=10.  The squares are also overlapping in the vertical scale.

 Steps to reproduce:
 Here are the commands I used to generate this:

 maptrees = function(n=1,a=1,b=1,h=2,view=horz,fg=1,np=FALSE,add=TRUE) {
    #n = tree density (#/m2)
    #a = crown horizontal radius (m)
    #b = crown vertical radius (m)
    #h = tree height (m)
    #view = horz, vert
    #np = TRUE if new plot desired

    if (np) {
        quartz(width=6, height=6)
        add=!np
        }

    dx = sqrt(1/n)
    x = rep(dx*(1:10),10)
    y = as.vector(t(matrix(x,10,10)))

    if (view==horz) {
        circles = rep(a,100)
        symbols(x=x,y=y,circles=circles, fg=fg,inches=FALSE,add=add)
        points(x,y,pch='.')
        mtext(paste(n=,n,, d=,dx,, a=,a))
    } else {
        #mtext(paste(n=,n,, d=,dx,, a=,a,, b=,b,, h=,h))

    }
    return(cbind(x,y,circles))
    }

 Commands:
    junk =maptrees(n= 0.01, a=5,add=FALSE)
    lines(c(0,100),c(45,45))
    lines(c(0,100),c(55,55))
    lines(c(0,100),c(50,50))

    lines(c(50,50),c(0,100))
    lines(c(55,55),c(0,100))
    lines(c(45,45),c(0,100))
    symbols(50,50,squares=10,fg=2, add=TRUE,inches=FALSE)
    symbols(50,60,squares=10,fg=2, add=TRUE,inches=FALSE)

 Actual results:  See attached plot.
 Expected results:  The circles and squares in the plot should be
 edge-to-edge,
 not overlapping in the vertical direction.
 Build Date and Platform: Build 2010-7-16 on Mac 10.5.8


 I am using a MacBookPro:
 platform       x86_64-apple-darwin9.8.0
 arch           x86_64
 os             darwin9.8.0
 system         x86_64, darwin9.8.0
 status
 major          2
 minor          11.1
 year           2010
 month          05
 day            31
 svn rev        52157
 language       R
 version.string R version 2.11.1 (2010-05-31)

 I could not find another bug report of this problem.

 Thanks to anyone who can help.

 Nancy Kiang

 --


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





-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] R graphic help

2010-07-18 Thread baptiste auguie
Hi,

There may be a simpler way but try this,

plot(10^jitter(seq(-2,4,length=10)), 1:10, log=x, xaxt=n)
axis(1, at = axTicks(1),labels = format(axTicks(1),scientific=FALSE))

HTH,

baptiste

On 18 July 2010 10:58, Timothy O'Brien teobr...@gmail.com wrote:
 Dear All,

 I've done some searching, but to no avail --

 I'm plotting x-y data via the plot command, and the log=x command.

 The graphed x values are in scientific notation (1e-02 1e-01 1e+00 etc).
 Might you have some idea on how I can get the plot to uses the x values
 (0.01 0.10 1.0 10.0 etc) instead?  A related Q - where might a good place to
 search for such answers?  I've tried using Google searches and reading some
 posted Manuals but ...

 Thanks,
 Tim O'Brien

        [[alternative HTML version deleted]]

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


Re: [R] Sum list elements

2010-07-27 Thread baptiste auguie
Hi,

do.call(sum, mylist)

?do.call

baptiste

On 27 July 2010 14:36, Nicola Sturaro Sommacal
mailingl...@nicolasturaro.com wrote:
 Hi!

 I have a list of 24 elements, all of the same type (dataframe, for example).

 I am looking for an alternative to mylist[[1]] + mylist[[2]] + ... +
 mylist[[24]] to obtain the sum.

 Anyone can help me?

 Thanks in advance.

 Nicola S.

        [[alternative HTML version deleted]]

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


Re: [R] hatching posibility in Panel.Polygon

2010-07-28 Thread baptiste auguie
Hi,

library(gridExtra)
example(patternGrob)

provides some patterns to fill a rectangular area using Grid graphics.
It could in theory be used in lattice. I wouldn't use it either, but I
can imagine how it might be useful on very special occasions.


Best,

baptiste




On 28 July 2010 06:11, HC hca...@yahoo.co.in wrote:

 Thank you for your follow up on this matter.

 I did think about the partial transparent color option and will certainly
 use it and see how it works out. For presentations and color prints, the
 partial transparency is surely going to work and may even look nicer. But
 for black and white printing for journal articles or making zerox copies,
 hatching seems more effective. And that was the reason of my exploring it.

 There may be some valid reason to be disappointed if such option is made
 available. However, such an option will only add more power to the trellis
 graphics that already very useful, attractive and efficient.

 Regards.
 HC



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/hatching-posibility-in-Panel-Polygon-tp2301863p2304414.html
 Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Output (graphics and table/text)

2010-08-05 Thread baptiste auguie
Hi,

To add tables, the gplots package has a textplot() function, and for
Grid graphics there is a grid.table() function in gridExtra.

HTH,

baptiste

On 5 August 2010 00:02, Ralf B ralf.bie...@gmail.com wrote:
 Hi R Users,

 I need to produce a simple report consisting of some graphs and a
 statistic. Here simplification of it:

 # graphics output test
 a - c(1,3,2,1,4)
 b - c(2,1,1,1,2)
 c - c(4,7,2,4,5)
 d - rnorm(500)
 e - rnorm(600)
 op - par(mfrow=c(3,2))
 pie(a)
 pie(b)
 pie(c)
 text(ks.test(d,e))

 obviously, the ks.test does not make it to the output. How can this be
 archived by a) simply dumpting the text into the fourth quad so that
 coordination is relative to the quarter? b) the output is actually
 presented as a little table without the need to use a LaTeX solution?

 Thanks a lot,
 Ralf

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


Re: [R] help to polish plot in ggplot2

2010-08-11 Thread baptiste auguie
Hi,

One way you could do it is to create a separate graph for each
category. The y axis labels would replace the strip labels. You could
then stack the graphs on the page, and add a common legend. The tricky
part would be to make sure the different panels have the same width
and height.

Another option might be to hack a custom Grob (gTree) for the y-axis
title so that it would draw the current y-axis title and also the
labels for the facets next to it. Of course you'd also get rid of the
strips in this case.

Best,

baptiste



On 11 August 2010 15:39, Mahbubul Majumder mahbu...@gmail.com wrote:
 Hi,

 I wanted to generate a plot which is almost like the plot generated by the
 following codes.

 category - paste(Geographical Category, 1:10)
 grp1 - rnorm(10, mean=10, sd=10)
 grp2 - rnorm(10, mean=20, sd=10)
 grp3 - rnorm(10, mean=15, sd=10)
 grp4 - rnorm(10, mean=12, sd=10)

 mydat - data.frame(category,grp1,grp2,grp3,grp4)

 dat.m - melt(mydat)

 p - qplot(1,value, data=dat.m, geom=bar,  xlab=,ylab=Percentage of eco
 change,stat=identity,fill=variable, position=dodge)
 p + coord_flip()+ facet_grid(category ~ .,
 space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y =
 theme_text(hjust = 0))


 Now the only modification I need from this plot is that I want the grid
 labels (text) on the left hand side with right justification and white
 background. My prospective plot should have labels like the the plot
 generated by the codes below. The reason why I don't like the plot below is
 that it does not show separate grid for each category.

 p - qplot(category,value, data=dat.m, geom=bar,  ylab=Percentage of eco
 change,stat=identity,fill=variable, position=dodge)
 p + coord_flip()

 Can you help me generate my vision plot?

 --
 Mahbub Majumder
 Graduate Student
 Dept. of Statistics
 Iowa State University

        [[alternative HTML version deleted]]

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


Re: [R] help to polish plot in ggplot2

2010-08-12 Thread baptiste auguie
To illustrate the second option I proposed,

library(ggplot2)
library(gridExtra)

category - paste(Geographical Category, 1:10)

grp1 - rnorm(10, mean=10, sd=10)
grp2 - rnorm(10, mean=20, sd=10)
grp3 - rnorm(10, mean=15, sd=10)
grp4 - rnorm(10, mean=12, sd=10)

mydat - data.frame(category,grp1,grp2,grp3,grp4)

dat.m - melt(mydat)

p - qplot(1,value, data=dat.m, geom=bar,  xlab=,ylab=Percentage of eco
change,stat=identity,fill=variable, position=dodge) +
coord_flip()+ facet_grid(category ~ .,
space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y =
theme_text(hjust = 0))

labs - llply(category, textGrob)

## add a blank grob below as the y title is aligned with the full
ggplot2 height,
## not just the panel
my.labels - do.call(arrangeGrob, c(labs, list(ncol=1, left=My y
title, sub= )))
# grid.draw(my.labels)

## hack: define the width of my.labels
ylab - gTree(children=gList(my.labels, rectGrob()), cl=mylabels )

widthDetails.mylabels - function(x)
  max(stringWidth(category)) + unit(1, line)

## hack: tweak ggplot2's axis.title.y option to use our gTree
foo - function()
  function(label, x, y)
  ylab

p + opts(strip.text.y =theme_blank(),
 strip.background=theme_blank()) +
 opts(  axis.title.y = foo())

HTH,

baptiste


On 12 August 2010 07:44, baptiste auguie baptiste.aug...@googlemail.com wrote:
 Hi,

 One way you could do it is to create a separate graph for each
 category. The y axis labels would replace the strip labels. You could
 then stack the graphs on the page, and add a common legend. The tricky
 part would be to make sure the different panels have the same width
 and height.

 Another option might be to hack a custom Grob (gTree) for the y-axis
 title so that it would draw the current y-axis title and also the
 labels for the facets next to it. Of course you'd also get rid of the
 strips in this case.

 Best,

 baptiste



 On 11 August 2010 15:39, Mahbubul Majumder mahbu...@gmail.com wrote:
 Hi,

 I wanted to generate a plot which is almost like the plot generated by the
 following codes.

 category - paste(Geographical Category, 1:10)
 grp1 - rnorm(10, mean=10, sd=10)
 grp2 - rnorm(10, mean=20, sd=10)
 grp3 - rnorm(10, mean=15, sd=10)
 grp4 - rnorm(10, mean=12, sd=10)

 mydat - data.frame(category,grp1,grp2,grp3,grp4)

 dat.m - melt(mydat)

 p - qplot(1,value, data=dat.m, geom=bar,  xlab=,ylab=Percentage of eco
 change,stat=identity,fill=variable, position=dodge)
 p + coord_flip()+ facet_grid(category ~ .,
 space=free)+scale_x_discrete(breaks=c(2,4))+opts(strip.text.y =
 theme_text(hjust = 0))


 Now the only modification I need from this plot is that I want the grid
 labels (text) on the left hand side with right justification and white
 background. My prospective plot should have labels like the the plot
 generated by the codes below. The reason why I don't like the plot below is
 that it does not show separate grid for each category.

 p - qplot(category,value, data=dat.m, geom=bar,  ylab=Percentage of eco
 change,stat=identity,fill=variable, position=dodge)
 p + coord_flip()

 Can you help me generate my vision plot?

 --
 Mahbub Majumder
 Graduate Student
 Dept. of Statistics
 Iowa State University

        [[alternative HTML version deleted]]

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


Re: [R] find value between two other numbers?

2010-08-13 Thread baptiste auguie
Hi,

I see no need to construct the vector, try this instead,

belong = function(x=4, y=c(1,10))  x = y[2]  x = y[1]

see also ?findInterval

HTH,

baptiste

On 13 August 2010 01:10, fishkbob fishk...@gmail.com wrote:

 So basically I want to do this -

 4 %in% 1:10
 should return true

 Would there be another way of doing this without having to do the 1:10 part?

 I am using a very large data set and trying to do

 459124 %in% 103000:983000

 multiple times for many values, and it is taking quite a long time

 Also, I would like to vary the x:y part, so I can't even make an object that
 is c(x:y) and do a which(#=c(x:y)) because I would need to change x and y
 each time.
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/find-value-between-two-other-numbers-tp2323513p2323513.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 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] cacheSweave / pgfSweave driver for package vignette

2010-08-13 Thread baptiste auguie
Dear list,


I wish to use a specific driver to process an sweave document in the
inst/doc directory of a package. Specifically, I would like to use
either cacheSweave or pgfSweave to speed up the creation of the
vignette which requires lengthy computations. The same request would
also apply to the highlight driver, to provide syntax highlighting of
R chunks.

In writing R extensions I see that during R CMD BUILD Sweave is run
first, then optionally a makefile can be used to process any other
files. It doesn't seem to leave room for a choice of Sweave engine, as
far as I understand. One option I am thinking of is to change the
extension of the source file to something like .Rnw2 so that Sweave
ignores it altogether, and then use the appropriate command in a
makefile.

I have no experience in writing makefiles, so I'm hoping someone would
already have solved this issue and could provide some advice.

Sincerely,

baptiste

__
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] cacheSweave / pgfSweave driver for package vignette

2010-08-14 Thread baptiste auguie
Thank you everyone, I think I'll follow the technique used in Rcpp
(dummy vignettes + Makefile).
It would be great to have a mechanism to select the driver for
vignette generation though.

Also, as a side-note, the choice of a driver has its own shortcoming;
I cannot use the features of highlight and, say, pgfSweave in the same
document.

Sincerely,

baptiste

On 13 August 2010 11:10, Romain Francois romain.franc...@dbmail.com wrote:

 Hi,

 I've been meaning to ask the same question before.

 Le 13/08/10 11:01, baptiste auguie a écrit :

 Dear list,


 I wish to use a specific driver to process an sweave document in the
 inst/doc directory of a package. Specifically, I would like to use
 either cacheSweave or pgfSweave to speed up the creation of the
 vignette which requires lengthy computations. The same request would
 also apply to the highlight driver, to provide syntax highlighting of
 R chunks.

 In writing R extensions I see that during R CMD BUILD Sweave is run
 first, then optionally a makefile can be used to process any other
 files. It doesn't seem to leave room for a choice of Sweave engine, as
 far as I understand. One option I am thinking of is to change the
 extension of the source file to something like .Rnw2 so that Sweave
 ignores it altogether, and then use the appropriate command in a
 makefile.

 This is what we do in Rcpp to build our 7 vignettes (since we like to use
 the driver from highlight).

 One thing to have in mind is that R needs the .Rnw file to be present in doc
 once the package is installed, so that the vignette function works, hence
 some trickery in Rcpp.

 A way to control which sweave (and perhaps tangle) driver is to be used for
 a particular vignette would be very useful.

 Romain

 I have no experience in writing makefiles, so I'm hoping someone would
 already have solved this issue and could provide some advice.

 Sincerely,

 baptiste

 --
 Romain Francois
 Professional R Enthusiast
 +33(0) 6 28 91 30 30
 http://romainfrancois.blog.free.fr
 |- http://bit.ly/b8VNE2 : Rcpp at LondonR, oct 5th
 |- http://bit.ly/aAyra4 : highlight 0.2-2
 `- http://bit.ly/94EBKx : inline 0.3.6




__
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] grid.table and expression in table body?

2010-08-17 Thread baptiste auguie
On 17 August 2010 18:38, Johannes Graumann johannes_graum...@web.de wrote:
 Hi - I can't get this figured out ...

 Thanks for any hint.

The parse=TRUE argument means that all the table content will be
parsed and interpreted as expression. In your content you have invalid
expressions (e.g. text with spaces), which cause the error. You could
try to reformat the labels,

# replace the spaces
m = gsub( ,~,as.matrix(absoluteTable))
# wrap the  sign in 
m = gsub(,\\,m)
library(gridExtra)
grid.table(data.frame(m),parse=T)

but I don't see the point of using parse in your example (there is not
plotmath expression to render).

Of course, I welcome any suggestion to create a matrix of valid
expressions, I have no clue how to deal with these.

baptiste




 Joh

 load(/tmp/AbsoluteTable.Rdata)
 absolutetable
 library(gridExtra)
 grid.table(absoluteTable)#Works
 grid.table(absoluteTable,parse=TRUE)
 Error in parse(text = d[ii]) : unexpected symbol in Survey Scans

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-pc-linux-gnu

 locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
 [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

 attached base packages:
 [1] grid      stats     graphics  grDevices utils     datasets  methods
 [8] base

 other attached packages:
 [1] gridExtra_0.7

 loaded via a namespace (and not attached):
 [1] tools_2.11.1

 On Monday 09 August 2010 12:02:03 baptiste auguie wrote:
 I just uploaded version 0.7 on googlecode. I had inadvertently messed
 up the previous attempt (uploaded an older version from another
 computer). Fingers crossed it should build on r-forge in the next few
 days.

 baptiste

 On 6 August 2010 17:11, Johannes Graumann johannes_graum...@web.de wrote:
  I updated the package from r-forge, but despite the fact that
  grid.table does not complain about the parse option if given, your
  example below is not being printed as a parsed expression.
 
  How can I check the actual version of the installed/loaded gridExtra
  package?
 
  Thanks, Joh
 
  On Wednesday 04 August 2010 16:47:12 you wrote:
  I added a parse argument to grid.table so that when switched to TRUE
  (default FALSE) all the text strings are interpreted as expressions
  (inspired by ggplot2::geom_text),
 
  d - data.frame(alpha, beta)
  grid.table(d, parse=T)
 
  you'll need revision 258 of gridExtra for this to work (googlecode now,
  r-forge in the following days, CRAN in the next stable version).
 
  HTH,
 
  baptiste
 
  On Aug 4, 2010, at 9:56 AM, Johannes Graumann wrote:
   Hi Baptiste,
  
   This is, I fear a bit beyond my level of competency ... What I want to
   be able to do is things like put 2.2%*%10^{-16} in a table cell,
   who's name I can already set to p[Wilcoxon] ...
  
   Joh
  
   On Wednesday 04 August 2010 09:15:43 you wrote:
   Hi,
  
   I don't know the answer to your question (how to make a data.frame
   with expressions), but if you have a list of expressions you could
   try the following,
  
   http://code.google.com/p/gridextra/wiki/testExpressions
  
   I'm open to suggestions for your original query (what is the best way
   to do it – parse each string and coerce it as an expression?)
  
   HTH,
  
   baptiste
  
   On Aug 4, 2010, at 12:05 AM, Johannes Graumann wrote:
   Hi,
  
   Is there any way to get an expression into a data.frame, such that
   grid.table from gridExtra will plot it evaluated in the table
   body? The docu does it for the header, but is the body possible?
  
   Thanks, Joh
  
   __
   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.


Re: [R] plotmath question

2010-08-19 Thread baptiste auguie
Try this,

b = 20

plot(1, ylab= bquote(italic(P) * .(b))  )

HTH,

baptiste

On 19 August 2010 20:02, array chip arrayprof...@yahoo.com wrote:
 Hi all, let me give a simple example:

 b-20
 I would like to print ylab as P20 where P is printed in Italic font. When 
 I
 do the following:

 plot(1, ylab=expression(paste(italic(P),b,sep=)))

 I got y axis label printed as Pb instead of P20. What is the best solution
 to print platmath symbols with value of the variable at the same time?

 Thanks

 John

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




-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] R-level expansion of Rplot%03d.png

2010-08-21 Thread baptiste auguie
Dear list,

I'm using the brew package to generate a report containing various
plots. I wrote a function that creates a plot in png and pdf formats,
and outputs a suitable text string to insert the file in the final
document using the asciidoc syntax,

%
tmp - 1
makePlot = function(p, name=paste(tmp,tmp,sep=), width=300)
{
png(paste(name,.png,sep=))
print(p)
dev.off()
pdf(paste(name,.pdf,sep=))
print(p)
dev.off()
cat(noquote(paste('image:',name,'.png[',name,',width=',width,',link=',name,'.pdf]',sep=)))
tmp - tmp + 1
}
%

The resulting html file contains a thumbnail of the png file, with a
link to the pdf file.

I'm not happy with my default filename for the graphics. Is there a
way to expand the default filename of R graphic devices? I would like
to call it like this,


makePlot = function(p, name=Rplot%03d, width=300)
{

real.name = expandName(name) # function needed here
png(paste(name,.png,sep=))
print(p)
dev.off()
pdf(paste(name,.pdf,sep=))
print(p)
dev.off()
cat(noquote(paste('image:',real.name,'.png[',real.name,',width=',width,',link=',real.name,'.pdf]',sep=)))
}


Sincerely,

baptiste

__
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] R-level expansion of Rplot%03d.png

2010-08-21 Thread baptiste auguie
My function needs to do two things with the filename:

First, create the plot file. For this, Rplot%03d is OK because it is
correctly interpreted by the graphics device.

Second, generate a text string referring to this filename. This is
where I need to convert Rplot%03d to, say, Rplot001. I am assuming
that it is implemented internally by looking at the files in the
current directory with some regular expression search, and
incrementing the end number as needed. I wonder if there's a high
level function to perform this task.

Best,

baptiste

On 21 August 2010 13:35, kees duineveld kees.duinev...@gmail.com wrote:
 Not sure what you want. Plot does that automatically. It seems to use
 path.expand() to make the %03d expansion. Not that path.expand() is
 documented to do this, but it seem to work.

 Kees

 On Sat, 21 Aug 2010 13:04:54 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 Dear list,

 I'm using the brew package to generate a report containing various
 plots. I wrote a function that creates a plot in png and pdf formats,
 and outputs a suitable text string to insert the file in the final
 document using the asciidoc syntax,

 %
 tmp - 1
 makePlot = function(p, name=paste(tmp,tmp,sep=), width=300)
 {
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()

 cat(noquote(paste('image:',name,'.png[',name,',width=',width,',link=',name,'.pdf]',sep=)))
 tmp - tmp + 1
 }
 %

 The resulting html file contains a thumbnail of the png file, with a
 link to the pdf file.

 I'm not happy with my default filename for the graphics. Is there a
 way to expand the default filename of R graphic devices? I would like
 to call it like this,


 makePlot = function(p, name=Rplot%03d, width=300)
 {

 real.name = expandName(name) # function needed here
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()

 cat(noquote(paste('image:',real.name,'.png[',real.name,',width=',width,',link=',real.name,'.pdf]',sep=)))
 }


 Sincerely,

 baptiste

 __
 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-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] R-level expansion of Rplot%03d.png

2010-08-21 Thread baptiste auguie
I dunno, it doesn't seem to do it for me,

name = Rplot%03d.png
real.name = path.expand(name)
real.name
#[1] Rplot%03d.png
list.files(patt=.png)
#[1] Rplot001.png

sessionInfo()
R version 2.11.1 (2010-05-31)
i386-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base



On 21 August 2010 14:15, kees duineveld kees.duinev...@gmail.com wrote:
 Now I understand. You need the name which png() does not return.
 So I think you need to do (untested, I am struggling with the cat()):


 makePlot = function(p, name=Rplot%03d, width=300)
 {
 real.name.png = path.expand(paste(name,'.png'sep='') # function needed here
 real.name.pdf = path.expand(paste(name,'.pdf'sep='') # function needed here
 png(real.name.png)
 print(p)
 dev.off()
 pdf(real.name.pdf)
 print(p)
 dev.off()
 cat(noquote(paste('image:',real.name.png,',width=',width,',link=real.name.pdf)
 }

 On Sat, 21 Aug 2010 14:02:04 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 My function needs to do two things with the filename:

 First, create the plot file. For this, Rplot%03d is OK because it is
 correctly interpreted by the graphics device.

 Second, generate a text string referring to this filename. This is
 where I need to convert Rplot%03d to, say, Rplot001. I am assuming
 that it is implemented internally by looking at the files in the
 current directory with some regular expression search, and
 incrementing the end number as needed. I wonder if there's a high
 level function to perform this task.

 Best,

 baptiste

 On 21 August 2010 13:35, kees duineveld kees.duinev...@gmail.com wrote:

 Not sure what you want. Plot does that automatically. It seems to use
 path.expand() to make the %03d expansion. Not that path.expand() is
 documented to do this, but it seem to work.

 Kees

 On Sat, 21 Aug 2010 13:04:54 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 Dear list,

 I'm using the brew package to generate a report containing various
 plots. I wrote a function that creates a plot in png and pdf formats,
 and outputs a suitable text string to insert the file in the final
 document using the asciidoc syntax,

 %
 tmp - 1
 makePlot = function(p, name=paste(tmp,tmp,sep=), width=300)
 {
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()


 cat(noquote(paste('image:',name,'.png[',name,',width=',width,',link=',name,'.pdf]',sep=)))
 tmp - tmp + 1
 }
 %

 The resulting html file contains a thumbnail of the png file, with a
 link to the pdf file.

 I'm not happy with my default filename for the graphics. Is there a
 way to expand the default filename of R graphic devices? I would like
 to call it like this,


 makePlot = function(p, name=Rplot%03d, width=300)
 {

 real.name = expandName(name) # function needed here
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()


 cat(noquote(paste('image:',real.name,'.png[',real.name,',width=',width,',link=',real.name,'.pdf]',sep=)))
 }


 Sincerely,

 baptiste

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



 --
 Using Opera's revolutionary email client: http://www.opera.com/mail/


__
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] R-level expansion of Rplot%03d.png

2010-08-21 Thread baptiste auguie
Dear Prof. Ripley,

Thank you for the authoritative information. I will implement my own
file numbering scheme, but I'm surprised it was never asked for in all
those years. It seems like a useful feature, to know what your output
filename will be.

Thanks again,

baptiste

On 21 August 2010 18:27, Prof Brian Ripley rip...@stats.ox.ac.uk wrote:
 Just so this thread is complete on the record:

 Filenames such as Rplot%03d.png are used in C code as format strings when
 opening a file.  Nothing in R subsequently knows the file name -- the file
 is accessed through the FILE* pointer.

 Despite what baptiste 'assumes', it is clearly documented that the string is
 used to format the *page number*: there is no regex search. E.g. (?png,
 Unix)

 filename: the name of the output file.  The page number is substituted
          if a C integer format is included in the character string, as
          in the default.

 There is no API to find the current page number, nor AFAIR in all the years
 of the R graphics device API has anyone asked for one.

 If I wanted to do anything like this I would expect to generate filenames
 myself and open a new png() device for each plot.  But the alternative is to
 count the number of pages your code generates (which may need detailed
 knowledge of what the plot commands do).


 On Sat, 21 Aug 2010, kees duineveld wrote:

 You are correct. (I really should start using these reading glasses).

 My apologies

 On Sat, 21 Aug 2010 14:20:17 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 I dunno, it doesn't seem to do it for me,

 name = Rplot%03d.png
 real.name = path.expand(name)
 real.name
 #[1] Rplot%03d.png
 list.files(patt=.png)
 #[1] Rplot001.png

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 i386-apple-darwin9.8.0

 locale:
 [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

 attached base packages:
 [1] stats     graphics  grDevices utils     datasets  methods   base



 On 21 August 2010 14:15, kees duineveld kees.duinev...@gmail.com wrote:

 Now I understand. You need the name which png() does not return.
 So I think you need to do (untested, I am struggling with the cat()):


 makePlot = function(p, name=Rplot%03d, width=300)
 {
 real.name.png = path.expand(paste(name,'.png'sep='') # function needed
 here
 real.name.pdf = path.expand(paste(name,'.pdf'sep='') # function needed
 here
 png(real.name.png)
 print(p)
 dev.off()
 pdf(real.name.pdf)
 print(p)
 dev.off()

 cat(noquote(paste('image:',real.name.png,',width=',width,',link=real.name.pdf)
 }

 On Sat, 21 Aug 2010 14:02:04 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 My function needs to do two things with the filename:

 First, create the plot file. For this, Rplot%03d is OK because it is
 correctly interpreted by the graphics device.

 Second, generate a text string referring to this filename. This is
 where I need to convert Rplot%03d to, say, Rplot001. I am assuming
 that it is implemented internally by looking at the files in the
 current directory with some regular expression search, and
 incrementing the end number as needed. I wonder if there's a high
 level function to perform this task.

 Best,

 baptiste

 On 21 August 2010 13:35, kees duineveld kees.duinev...@gmail.com
 wrote:

 Not sure what you want. Plot does that automatically. It seems to use
 path.expand() to make the %03d expansion. Not that path.expand() is
 documented to do this, but it seem to work.

 Kees

 On Sat, 21 Aug 2010 13:04:54 +0200, baptiste auguie
 baptiste.aug...@googlemail.com wrote:

 Dear list,

 I'm using the brew package to generate a report containing various
 plots. I wrote a function that creates a plot in png and pdf formats,
 and outputs a suitable text string to insert the file in the final
 document using the asciidoc syntax,

 %
 tmp - 1
 makePlot = function(p, name=paste(tmp,tmp,sep=), width=300)
 {
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()



 cat(noquote(paste('image:',name,'.png[',name,',width=',width,',link=',name,'.pdf]',sep=)))
 tmp - tmp + 1
 }
 %

 The resulting html file contains a thumbnail of the png file, with a
 link to the pdf file.

 I'm not happy with my default filename for the graphics. Is there a
 way to expand the default filename of R graphic devices? I would like
 to call it like this,


 makePlot = function(p, name=Rplot%03d, width=300)
 {

 real.name = expandName(name) # function needed here
 png(paste(name,.png,sep=))
 print(p)
 dev.off()
 pdf(paste(name,.pdf,sep=))
 print(p)
 dev.off()



 cat(noquote(paste('image:',real.name,'.png[',real.name,',width=',width,',link=',real.name,'.pdf]',sep=)))
 }


 Sincerely,

 baptiste

 __
 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] graphing plots of plots

2010-08-21 Thread baptiste auguie
Hi,


I think you could do it quite easily with lattice,

library(lattice)

latticeGrob - function(p, ...){
   grob(p=p, ..., cl=lattice)
}
drawDetails.lattice - function(x, recording=FALSE){
   lattice:::plot.trellis(x$p, newpage=FALSE)
}

plots - replicate(4, xyplot(rnorm(10)~rnorm(10),xlab=,ylab=), simplify=F)

my.vp - function(x,y)
viewport(x=x,y=y,default.units=native,width=unit(1, cm),
height=unit(1,cm))

my.panel = function(x, y, ...){
  ind - seq_along(x)
  for (ii in ind){
g - latticeGrob(plots[[ii]], vp=my.vp(x[ii],y[ii]))
grid.draw(g)
  }
}

xyplot(1:4~1:4, panel = my.panel)

HTH,

baptiste

On 21 August 2010 22:11, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote:
 On Sat, Aug 21, 2010 at 8:48 PM, r.ookie r.oo...@live.com wrote:
 I'm trying to understand your question because when I think of a graph, I 
 think of one canvas, on which, various functions are plotted (a function can 
 be one point for example).

 So, when you say each 'element' do you mean each function?
 If so, then that seems to be asking how to plot a function per graph (which 
 is probably obvious and not what you're asking)

 How about you clarify first :)


  Sounded to me a bit like plotting pie charts at the locations of
 countries on a map. Or something better (not hard).

  subplot from Hmisc?

  library(Hmisc)
  example(subplot)

 Barry

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


Re: [R] Draw a perpendicular line?

2010-08-25 Thread baptiste auguie
hi,

also, make sure you have set the aspect ratio to 1:1 when plotting (asp=1).

HTH,

baptiste

On 25 August 2010 10:20, Benno Pütz pu...@mpipsykl.mpg.de wrote:
 Maybe

 perp.slope = -1/slope
 abline(cy - cx*perp.slope, perp.slope)

 where cx, cy are x- and y-coordinate of C, resp., and slope the slope you 
 calculated for the line through A and B


 Am 24.Aug.2010 um 0:04 schrieb CZ:


 Hi,

 I am trying to draw a perpendicular line from a point to two points.
 Mathematically I know how to do it, but to program it, I encounter some
 problem and hope can get help.  Thanks.

 I have points, A, B and C.  I calculate the slope and intercept for line
 drawn between A and B.
 I am trying to check whether I can draw a perpendicular line from C to line
 AB and get the x,y value for the point D at the intersection.

 Assume I get the slope of the perpendicular line, I will have my point (D)
 using variable x and y which is potentially on line AB.   My idea was using
 |AC|*|AC| = |AD|*|AD|+ |CD|*|CD|.  I don't know what function I may need to
 call to calculate the values for point D (uniroot?).

 Thank you.



 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Draw-a-perpendicular-line-tp2335882p2335882.html
 Sent from the R help mailing list archive at Nabble.com.

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




-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] export 4D data as povray density files

2010-08-27 Thread baptiste auguie
Dear list,

I wish to visualise some 4D data as a kind of colour / translucent
cloud in 3D. I haven't seen such plots in R (but perhaps I missed a
feature of rgl). The easiest option I found would be to export the
data in povray's df3 (density file) format and visualise it with
povray.

The format specification baffles me a little,
http://www.povray.org/documentation/view/3.6.1/374/ ; fortunately I
found a few C++ utilities that could do the conversion from a plain
ascii datafile to this format. Basically, I wish to create a set of
xyz coordinates and a scalar function value in R, export it as a
regular ascii file, convert it to df3 and visualise it in povray.

An example of data from the R side would be,

N - 10
xx - seq(0,N)
d - expand.grid(x=xx,y=xx,z=xx)
d$t - runif(nrow(d), 0, 255)

cat(file=data.dat, 1 1 1\n)
write.table(d,file=data.dat,row.names = F,
col.names = F,append=T)

I wonder if anyone here ever played with this idea and could offer
some suggestions (I couldn't get it to work so far).

Best regards,

baptiste



-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] How to plot an expression-label with variable text

2010-08-27 Thread baptiste auguie
hi,

try this

lab =bquote(paste(Estimated , t[50], from ,.(what)))


HTH,

baptiste

On 27 August 2010 20:19, Dieter Menne dieter.me...@menne-biomed.de wrote:

 plot.new()
 lab =expression(paste(Estimated , t[50], from tgv))
 text(0.5,0.5,lab)
 # Should look the same as above. I could not get the substitute right:
 what = tgv
 lab =expression(paste(Estimated , t[50], from ,what))
 text(0.5,0.2,lab)


__
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] How to Adaptively Set Up the Coordinate Range of Multiple Graphs in One Figure

2010-08-31 Thread baptiste auguie
Hi,

It's easy with ggplot2,


library(ggplot2)

## create an empty plot
p - ggplot(map=aes(x,y))

## create a dummy list of data.frames with different ranges
d - replicate(4, data.frame(x=sample(1:10,1)+rnorm(10),
 y=sample(1:10,1)+rnorm(10)),
   simplify=FALSE)

## add lines to the plot step by step
for(ii in seq_along(d))
  p - p + geom_line(data = d[[ii]], color=ii)

HTH,

baptiste

On 31 August 2010 12:26, Wonsang You y...@ifn-magdeburg.de wrote:

 Hi, R-Helpers,

 I would like to ask about multiple graphs in one figure. I tried to execute
 the following codes.

  xlim - c(1,100)

 ylim - c(1,4)

 plot(NA, xlim=xlim, ylim=ylim)


 x - c(1:100)

 for(j in seq(1,10,by=1)) {

     y - j*x^2+log(j)

     lines(x, y)

 }


 In the above codes, I had to  arbitrarily set up the coordinate range of the
 figure in advance before calculating the values y. (seexlim and ylim)
 In results, the figure did not contain all data since most of data were
 outside the predefined range.
 I am wondering about how to control xlim and ylim adaptive to the real range
 of data, in order to include all data in the figure.
 Thank you for your great help and contribution.

 Best Regards,
 Stephen You


 -
 --
 Wonsang You
 Special Lab Non-Invasive Brain Imaging
 Leibniz Institute for Neurobiology
 http://www.ifn-magdeburg.de
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/How-to-Adaptively-Set-Up-the-Coordinate-Range-of-Multiple-Graphs-in-One-Figure-tp2401337p2401337.html
 Sent from the R help mailing list archive at Nabble.com.

        [[alternative HTML version deleted]]

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




-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] Please explain do.call in this context, or critique to stack this list faster

2010-09-05 Thread baptiste auguie
Another way that I like is reshape::melt.list() because it keeps track
of the name of the original data.frames,

l = replicate(1e4, data.frame(x=rnorm(100),y=rnorm(100)), simplify=FALSE)
system.time(a - rbind.fill(l))
#   user  system elapsed
# 2.482   0.111   2.597
system.time(b - melt(l,id=1:2))
#   user  system elapsed
#  6.556   0.229   6.801
system.time(c - do.call(rbind, l))
#  user  system elapsed
# 55.020  71.356 129.300

all.equal(a, b[ , -3])
#[1] TRUE

baptiste

On 5 September 2010 04:48, Hadley Wickham had...@rice.edu wrote:
 One common way around this is to pre-allocate memory and then to
 populate the object using a loop, but a somewhat easier solution here
 turns out to be ldply() in the plyr package. The following is the same
 idea as do.call(rbind, l), only faster:

 system.time(u3 - ldply(l, rbind))
   user  system elapsed
   6.07    0.01    6.09

 I think all you want here is rbind.fill:

 system.time(a - rbind.fill(l))
   user  system elapsed
  1.426   0.044   1.471

 system.time(b - do.call(rbind, l))
   user  system elapsed
     98      60     162

 all.equal(a, b)
 [1] TRUE

 This is considerably faster than do.call + rbind because I spend a lot
 of time working out how to do this most efficiently. You can see the
 underlying code at http://github.com/hadley/plyr/blob/master/R/rbind.r
 - it's relatively straightforward except for ensuring the output
 columns are the same type as the input columns.  This is a good
 example where optimised R code is much faster than C code.

 Hadley

 --
 Assistant Professor / Dobelman Family Junior Chair
 Department of Statistics / Rice University
 http://had.co.nz/

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




-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] Something similar to layout in lattice or ggplot

2010-09-07 Thread baptiste auguie
On 7 September 2010 17:19, Erik Iverson er...@ccbr.umn.edu wrote:
 See ?grid.layout or perhaps ?arrange from the gridExtra package.

gridExtra::grid.arrange(), rather.

baptiste

 Abhijit Dasgupta wrote:

 Hi,

 Is there a function similar to the layout function in base graphics in
 either lattice or ggplot? I'm hoping someone has written a function wrapper
 to the appropriate commands in grid that would make this easier :)

 Abhijit

        [[alternative HTML version deleted]]

 __
 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-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] Something similar to layout in lattice or ggplot

2010-09-07 Thread baptiste auguie
arrange() was renamed grid.arrange() when plyr started using this name
for a different function. I think it happened in version 0.6.5 of
gridExtra. The current version on CRAN is 0.7.

baptiste

On 7 September 2010 17:46, Erik Iverson er...@ccbr.umn.edu wrote:


 baptiste auguie wrote:

 On 7 September 2010 17:19, Erik Iverson er...@ccbr.umn.edu wrote:

 See ?grid.layout or perhaps ?arrange from the gridExtra package.

 gridExtra::grid.arrange(), rather.

 Do I have an old version of gridExtra?

 I have ?arrange:


 arrange               package:gridExtra                R Documentation

 arrange

 Description:

     arrange ggplot2, lattice, and grobs on a page

 Usage:

     arrange(..., as.table=FALSE, plot=TRUE, clip=TRUE, main, sub, left,
         legend, newpage=FALSE)

 Arguments:

     ...: plots of class ggplot2, trellis, or grobs, and valid
          arguments to grid.layout




 baptiste

 Abhijit Dasgupta wrote:

 Hi,

 Is there a function similar to the layout function in base graphics in
 either lattice or ggplot? I'm hoping someone has written a function
 wrapper
 to the appropriate commands in grid that would make this easier :)

 Abhijit

       [[alternative HTML version deleted]]

 __
 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-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] Matrixes inside matrixes

2010-09-08 Thread baptiste auguie
Hi,

You can have each cell of a matrix contain a matrix, but for a reason
that is just not clear to me the matrices are wrapped in a list,

m = matrix(replicate(4,matrix(1:9,3,3),simplify=FALSE), 2,2)

m[1,2][[1]]

str(m)

and even more surprising to me, m itself has become a list for some reason.

baptiste



On 8 September 2010 17:22, Alaios ala...@yahoo.com wrote:
 Hello everyone,

 Could you please help me find out if R supports matrixes inside matrixes?
 This is what I would like to do

 I have an area map of humidity per km. I would like at every cell to keep also
 information about the height of this area, the current temperature etc.

 Is something like that supported?

 I would like to thank you in advance for your help

 Best Regards
 Alex




        [[alternative HTML version deleted]]

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


Re: [R] large files produced from image plots?

2010-09-08 Thread baptiste auguie
Hi,

I get the same crash with x11() with sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] grid  stats graphics  grDevices utils datasets  methods
[8] base

However it works fine with quartz(). Have you tried other devices?
pdf() doesn't crash R for me, but the output is incorrect. png() is OK
but defeats the purpose here.

rasterImage is quite a recent addition, it would probably be
appreciated to report any such odd behavior to R-devel. Interestingly
(or not), the x11() test does not crash for me using grid.raster
instead of rasterImage.

Best,

baptiste







On 8 September 2010 21:47, Stephen T. obsessiv...@hotmail.com wrote:
 Hi Baptiste,
 Thanks for your suggestion. I have to look into this further, but anything I
 try with rasterImage() gives me this type of error (below is from running
 the example in the help file). This is with R 2.11.1 on OS X 10.5 -
  *** caught bus error ***
 address 0x24, cause 'non-existent physical address'
 Traceback:
  1: rasterImage(image, 100, 300, 150, 350, interpolate = FALSE)
 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace
 This is not an obvious error, is it?
 Thanks,
 Stephen
 Subject: Re: [R] large files produced from image plots?
 From: baptiste.aug...@googlemail.com
 Date: Wed, 8 Sep 2010 19:41:46 +0200
 CC: r-help@r-project.org
 To: obsessiv...@hotmail.com

 Hi,

 Have you tried the recent rasterImage() function?

 HTH,

 baptiste

 On Sep 8, 2010, at 7:30 PM, Stephen T. wrote:

 
  Hi list,
  I wonder if anyone has thoughts on making image plots in R [using
  image() or image.plot(), or filled.contour()]- I've made quite a bit now,
  but they seem quite large in size when exported to pdf file format (even
  after compressing with pdftk or ghostscript, which I regularly do). I know
  that for images, raster graphics output (png, tiff) may be the way to go,
  but often the ones I make are multi-panel plots with other graphics on 
  them,
  and are usually included in a LaTeX document (PDFLaTeX does accept png) and
  require stretching/shrinking (and/or possibly editing with Adobe
  Illustrator). I have had some luck exporting image plots from Matlab (to
  postscript or pdf) before in the sense that the files seem smaller and less
  pixelated. Is this a difference in the way image() plots are produced, or
  with the way the image is written to the pdf() device (if anyone is 
  familiar
  with other image-exporting programs...)? The other day I had a 13MB 
  dataset,
  and probably plotted 3/4 of it!
  using image() and the compressed pdf output was about 8 MB (it contained
  other stuff but was an addition of a few KB). I tried filled.contour(), as 
  I
  understand that it colors polygons to fill contours instead of coloring
  rectangles at each pixel - and it has saved me before - but this time the
  contours may have been too sharp as as its compressed pdf came out to be 62
  MB... (ouch!). I have not tested this data set with other software programs
  so it may just have been a difficult data set.
  Is there a good solution to this (or is it simply not to use a
  vector-graphics format in these instances), and just for my curiosity, are
  you aware of any things that other software (data analysis) programs do 
  uder
  the hood to make their exported images smaller/smoother?
  Thanks much!
  Stephen
  [[alternative HTML version deleted]]
 
  __
  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] scalable delimiters in plotmath

2010-09-09 Thread baptiste auguie
Dear list,

I read in ?plotmath that I can use bgroup to draw scalable delimiters
such as [ ] and ( ). The same technique fails with   however, and I
cannot find a workaround,

grid.text(expression(bgroup(,atop(x,y),)))

Error in bgroup(, atop(x, y), ) : invalid group delimiter

Regards,

baptiste

sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] grid  stats graphics  grDevices utils datasets
methods   base

other attached packages:
[1] TeachingDemos_2.7

loaded via a namespace (and not attached):
[1] tools_2.11.1

__
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] scalable delimiters in plotmath

2010-09-11 Thread baptiste auguie
What do people use to show angle brackets   in R graphics? Have I
missed something obvious?

Thanks,

baptiste

On 9 September 2010 17:57, baptiste auguie
baptiste.aug...@googlemail.com wrote:
 Dear list,

 I read in ?plotmath that I can use bgroup to draw scalable delimiters
 such as [ ] and ( ). The same technique fails with   however, and I
 cannot find a workaround,

 grid.text(expression(bgroup(,atop(x,y),)))

 Error in bgroup(, atop(x, y), ) : invalid group delimiter

 Regards,

 baptiste

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 locale:
 [1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

 attached base packages:
 [1] grid      stats     graphics  grDevices utils     datasets
 methods   base

 other attached packages:
 [1] TeachingDemos_2.7

 loaded via a namespace (and not attached):
 [1] tools_2.11.1


__
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] scalable delimiters in plotmath

2010-09-12 Thread baptiste auguie
Thanks everyone. I've also had a look at plotmath.c where bgroup is
defined for [, {, (, . but not . It seems quite trivial to
add it, at first sight, however there is a part that I don't
understand in the RenderDelim routine,

static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc,
pGEcontext gc, pGEDevDesc dd)
{

// [... snipped ...]

case '(':
top = 230; ext = 231; bot = 232; mid = 0;
break;
case ')':
top = 246; ext = 247; bot = 248; mid = 0;
break;

These integer codes make no sense to me, I have no clue which ones I
should use for  and . As far as I understand these codes might
correspond to extended ascii characters whose boundaries and positions
we want to borrow. Then again, maybe it's something else entirely.

Any hints?

Best wishes,

baptiste




On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net wrote:

 On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote:

 On 2010-09-11 16:14, Dennis Murphy wrote:

 Hi Baptiste,

 You need to use the symbol(\nnn) concept, where nnn denotes the octal
 symbol number. For  it's 074 and for  it's 076. This little test seemed
 to
 work:

 plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076)))

 HTH,
 Dennis

 It's a matter of taste, but I would use \341 and \361.
 However, these are still not scalable, AFAICS.

 Not exactly scalable angles, but you can fake it:

 plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y)
 )~symbol(\361)), cex.main=3)

 scriptstyle shrinks the inner atop() material, and since I tested on a Mac
 it should work for Baptiste.

 --
 David.

  -Peter Ehlers


 On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie
 baptiste.aug...@googlemail.com  wrote:

 What do people use to show angle brackets    in R graphics? Have I
 missed something obvious?

 Thanks,

 baptiste

 On 9 September 2010 17:57, baptiste auguie
 baptiste.aug...@googlemail.com  wrote:

 Dear list,

 I read in ?plotmath that I can use bgroup to draw scalable delimiters
 such as [ ] and ( ). The same technique fails with    however, and I
 cannot find a workaround,

 grid.text(expression(bgroup(,atop(x,y),)))

 Error in bgroup(, atop(x, y),) : invalid group delimiter

 Regards,

 baptiste

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 David Winsemius, MD
 West Hartford, CT

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


Re: [R] scalable delimiters in plotmath

2010-09-12 Thread baptiste auguie
Oh, right I see. I was completely off then. Maybe it's not so easy to
add  delimiters after all, I'll have to look at the list of symbol
pieces to see if these can be constructed too.

Thanks,

baptiste

On 12 September 2010 21:42, David Winsemius dwinsem...@comcast.net wrote:

 On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote:

 Thanks everyone. I've also had a look at plotmath.c where bgroup is
 defined for [, {, (, . but not . It seems quite trivial to
 add it, at first sight, however there is a part that I don't
 understand in the RenderDelim routine,

 static BBOX RenderDelim(int which, double dist, int draw, mathContext *mc,
                        pGEcontext gc, pGEDevDesc dd)
 {

 // [... snipped ...]

   case '(':
        top = 230; ext = 231; bot = 232; mid = 0;
        break;
   case ')':
        top = 246; ext = 247; bot = 248; mid = 0;
        break;

 These integer codes make no sense to me, I have no clue which ones I
 should use for  and .

 Does this help? (I think they are using Symbol PS fonts with decimal
 indexing.)

 as.octmode(c(230, 231, 232, 246, 247, 248) )
 [1] 346 347 350 366 367 370
  plot(1,1, xlab= expression(
 symbol(\346)~    # upper 1/3 of left paren
 symbol(\347)~    # to left of center bar
 symbol(\350)~    # lower 1/3 of left paren

 symbol(\366)~    # upper 1/3 of right paren
 symbol(\367)~    # to right of center bar
 symbol(\370) ) ) # lower 1/3 of right paren

 (caveat: Maybe not standard glyph-names.)

 I added octal annotation to the TestChars(font=5) call that the points help
 page offers:

 TestChars(font=5)
 for(j in 1:14) {
    for(i in 0:16){
        text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}}

 I do not see a trio or pair of glyphs that would form an angle bracket.

 --

 David.


 As far as I understand these codes might
 correspond to extended ascii characters whose boundaries and positions
 we want to borrow. Then again, maybe it's something else entirely.

 Any hints?

 Best wishes,

 baptiste




 On 12 September 2010 03:27, David Winsemius dwinsem...@comcast.net
 wrote:

 On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote:

 On 2010-09-11 16:14, Dennis Murphy wrote:

 Hi Baptiste,

 You need to use the symbol(\nnn) concept, where nnn denotes the octal
 symbol number. For  it's 074 and for  it's 076. This little test
 seemed
 to
 work:

 plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076)))

 HTH,
 Dennis

 It's a matter of taste, but I would use \341 and \361.
 However, these are still not scalable, AFAICS.

 Not exactly scalable angles, but you can fake it:

 plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y)
 )~symbol(\361)), cex.main=3)

 scriptstyle shrinks the inner atop() material, and since I tested on a
 Mac
 it should work for Baptiste.

 --
 David.

  -Peter Ehlers


 On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie
 baptiste.aug...@googlemail.com  wrote:

 What do people use to show angle brackets    in R graphics? Have I
 missed something obvious?

 Thanks,

 baptiste

 On 9 September 2010 17:57, baptiste auguie
 baptiste.aug...@googlemail.com  wrote:

 Dear list,

 I read in ?plotmath that I can use bgroup to draw scalable delimiters
 such as [ ] and ( ). The same technique fails with    however, and
 I
 cannot find a workaround,

 grid.text(expression(bgroup(,atop(x,y),)))

 Error in bgroup(, atop(x, y),) : invalid group delimiter

 Regards,

 baptiste

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 David Winsemius, MD
 West Hartford, CT




__
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] scalable delimiters in plotmath

2010-09-12 Thread baptiste auguie
I see, thanks. Looking at this table I guess the short answer is no,
these cannot be made to scale and the only ones that could have
already been implemented in bgroup().

Thanks,

baptiste


On 12 September 2010 22:11, Paul Murrell p.murr...@auckland.ac.nz wrote:
 Hi

 On 13/09/2010 7:57 a.m., baptiste auguie wrote:

 Oh, right I see. I was completely off then. Maybe it's not so easy to
 add  delimiters after all, I'll have to look at the list of symbol
 pieces to see if these can be constructed too.

 The plotmath stuff assumes a font with an Adobe Symbol encoding.  The
 characters we have to play with are shown at
 http://www.stat.auckland.ac.nz/~paul/R/CM/AdobeSym.pdf.
 You can see the components of growable delimiters on the bottom two rows.

 Paul

 Thanks,

 baptiste

 On 12 September 2010 21:42, David Winsemiusdwinsem...@comcast.net
  wrote:

 On Sep 12, 2010, at 6:15 AM, baptiste auguie wrote:

 Thanks everyone. I've also had a look at plotmath.c where bgroup is
 defined for [, {, (, . but not . It seems quite trivial to
 add it, at first sight, however there is a part that I don't
 understand in the RenderDelim routine,

 static BBOX RenderDelim(int which, double dist, int draw, mathContext
 *mc,
                        pGEcontext gc, pGEDevDesc dd)
 {

 // [... snipped ...]

   case '(':
        top = 230; ext = 231; bot = 232; mid = 0;
        break;
   case ')':
        top = 246; ext = 247; bot = 248; mid = 0;
        break;

 These integer codes make no sense to me, I have no clue which ones I
 should use for  and.

 Does this help? (I think they are using Symbol PS fonts with decimal
 indexing.)

 as.octmode(c(230, 231, 232, 246, 247, 248) )

 [1] 346 347 350 366 367 370
  plot(1,1, xlab= expression(
 symbol(\346)~    # upper 1/3 of left paren
 symbol(\347)~    # to left of center bar
 symbol(\350)~    # lower 1/3 of left paren

 symbol(\366)~    # upper 1/3 of right paren
 symbol(\367)~    # to right of center bar
 symbol(\370) ) ) # lower 1/3 of right paren

 (caveat: Maybe not standard glyph-names.)

 I added octal annotation to the TestChars(font=5) call that the points
 help
 page offers:

 TestChars(font=5)
 for(j in 1:14) {
    for(i in 0:16){
        text(i+0.2, j+.6, labels=as.octmode(i+(j+1)*16), cex=.5)}}

 I do not see a trio or pair of glyphs that would form an angle bracket.

 --

 David.


 As far as I understand these codes might
 correspond to extended ascii characters whose boundaries and positions
 we want to borrow. Then again, maybe it's something else entirely.

 Any hints?

 Best wishes,

 baptiste




 On 12 September 2010 03:27, David Winsemiusdwinsem...@comcast.net
 wrote:

 On Sep 11, 2010, at 9:00 PM, Peter Ehlers wrote:

 On 2010-09-11 16:14, Dennis Murphy wrote:

 Hi Baptiste,

 You need to use the symbol(\nnn) concept, where nnn denotes the
 octal
 symbol number. For    it's 074 and for    it's 076. This little
 test
 seemed
 to
 work:

 plot(1, 1, main = expression(symbol(\074)~'x, y'~symbol(\076)))

 HTH,
 Dennis

 It's a matter of taste, but I would use \341 and \361.
 However, these are still not scalable, AFAICS.

 Not exactly scalable angles, but you can fake it:

 plot(1, 1, main = expression(symbol(\341)~scriptstyle( atop(x,y)
 )~symbol(\361)), cex.main=3)

 scriptstyle shrinks the inner atop() material, and since I tested on a
 Mac
 it should work for Baptiste.

 --
 David.

  -Peter Ehlers


 On Sat, Sep 11, 2010 at 10:01 AM, baptiste auguie
 baptiste.aug...@googlemail.com    wrote:

 What do people use to show angle brackets        in R graphics?
 Have I
 missed something obvious?

 Thanks,

 baptiste

 On 9 September 2010 17:57, baptiste auguie
 baptiste.aug...@googlemail.com    wrote:

 Dear list,

 I read in ?plotmath that I can use bgroup to draw scalable
 delimiters
 such as [ ] and ( ). The same technique fails with    
  however, and
 I
 cannot find a workaround,

 grid.text(expression(bgroup(,atop(x,y),)))

 Error in bgroup(, atop(x, y),) : invalid group delimiter

 Regards,

 baptiste

 sessionInfo()
 R version 2.11.1 (2010-05-31)
 x86_64-apple-darwin9.8.0

 David Winsemius, MD
 West Hartford, CT




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

 --
 Dr Paul Murrell
 Department of Statistics
 The University of Auckland
 Private Bag 92019
 Auckland
 New Zealand
 64 9 3737599 x85392
 p...@stat.auckland.ac.nz
 http://www.stat.auckland.ac.nz/~paul/


__
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] bivariate vector numerical integration with infinite range

2010-09-21 Thread baptiste auguie
Dear list,

I'm seeking some advice regarding a particular numerical integration I
wish to perform.

The integrand f takes two real arguments x and y and returns a vector
of constant length N. The range of integration is [0, infty) for x and
[a,b] (finite) for y. Since the integrand has values in R^N I did not
find a built-in function to perform numerical quadrature, so I wrote
my own after some inspiration from a post in R-help,

library(statmod)

## performs 2D numerical integration
## using Gauss-Legendre quadrature
## with N points for x and y

vAverage - function(f, a1,b1, a2,b2, N=5, ...){

  GL - gauss.quad(N)
  nodes   - GL$nodes
  weights - GL$weights

  C2 - (b2 - a2) / 2
  D2 - (b2 + a2) / 2
  y - nodes*C2 + D2

  C1 - (b1 - a1) / 2
  D1 - (b1 + a1) / 2
  x - nodes*C1 + D1

  value - 0
  for (ii in seq_along(x)){
tmp - 0
for (jj in seq_along(y)){
  tmp - tmp + C1 * weights[jj] * f(x[jj], y[ii], ...)
}
value - value + C2 * weights[ii] * tmp
  }
  value
}

## test function, the result is pi for y=1
f - function(x, y) {
  res - 1 / (sqrt(x)*(1+x))
  c(res, res/2, 2*res)
}

## Transformation rule from Numerical Recipes
## to deal with the [0, infty) range of x

mixedrule - function(x, y, f, ...)
{
  t - exp(pi*sinh(x))
  dtdx - t*(pi*cosh(x))
  f(t, y, ...)*dtdx
}


vAverage(mixedrule, -4, 4, 0.0, 1, 20, f) - c(pi, pi/2, 2*pi)
## -3.535056e-06 -1.767528e-06 -7.070112e-06


So it seems to work. I wonder though if I may have missed an easier
(and more reliable) way to perform such integration using base
functions or an add-on package that I may have overlooked.

Best regards,

baptiste

__
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] puzzle with integrate over infinite range

2010-09-21 Thread baptiste auguie
Dear list,

I'm calculating the integral of a Gaussian function from 0 to
infinity. I understand from ?integrate that it's usually better to
specify Inf explicitly as a limit rather than an arbitrary large
number, as in this case integrate() performs a trick to do the
integration better.

However, I do not understand the following, if I shift the Gauss
function by some amount the integral should not be affected,

shiftedGauss - function(x0=500){
 integrate(function(x) exp(-(x-x0)^2/100^2), 0, Inf)$value
}

shift - seq(500, 800, by=10)
plot(shift, sapply(shift, shiftedGauss))

Suddenly, just after 700, the value of the integral drops to nearly 0
when it should be constant all the way. Any clue as to what's going on
here? I guess it's suddenly missing the important part of the range
where the integrand is non-zero, but how could this be overcome?

Regards,

baptiste


sessionInfo()
R version 2.11.1 (2010-05-31)
x86_64-apple-darwin9.8.0

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/C/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] inline_0.3.5RcppArmadillo_0.2.6 Rcpp_0.8.6
statmod_1.4.6

loaded via a namespace (and not attached):
[1] tools_2.11.1

__
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] bivariate vector numerical integration with infinite range

2010-09-21 Thread baptiste auguie
Hi,

thanks for the pointer to cubature (which i had probably dismissed too
quickly). Your tests with f should not work: the domain of f(x,.) is
restricted to positive reals, but this domain of integration is then
transformed in mixedrule() to map the semi-infinite range to a more
reasonable domain (for example [-4,4]).

Thanks,

baptiste




On 21 September 2010 14:16, David Winsemius dwinsem...@comcast.net wrote:
 Baptiste;

 You should see if this meets your requirements:

 help(adaptIntegrate, package=cubature)

 (I got errors when I ran the code and NaN's when I looked at the output of
 test function, f.)

 vAverage(mixedrule, -4, 4, 0.0, 1, 20, f) - c(pi, pi/2, 2*pi)
 Error: object 'mixedrule' not found

  f(-4,0)
 [1] NaN NaN NaN
 Warning message:
 In sqrt(x) : NaNs produced
  f(-3.9,0)
 [1] NaN NaN NaN
 Warning message:
 In sqrt(x) : NaNs produced
  f(-3.9,0.1)
 [1] NaN NaN NaN
 Warning message:
 In sqrt(x) : NaNs produced
 --
 David
 On Sep 21, 2010, at 4:11 AM, baptiste auguie wrote:

 Dear list,

 I'm seeking some advice regarding a particular numerical integration I
 wish to perform.

 The integrand f takes two real arguments x and y and returns a vector
 of constant length N. The range of integration is [0, infty) for x and
 [a,b] (finite) for y. Since the integrand has values in R^N I did not
 find a built-in function to perform numerical quadrature, so I wrote
 my own after some inspiration from a post in R-help,

 library(statmod)

 ## performs 2D numerical integration
 ## using Gauss-Legendre quadrature
 ## with N points for x and y

 vAverage - function(f, a1,b1, a2,b2, N=5, ...){

  GL - gauss.quad(N)
  nodes   - GL$nodes
  weights - GL$weights

  C2 - (b2 - a2) / 2
  D2 - (b2 + a2) / 2
  y - nodes*C2 + D2

  C1 - (b1 - a1) / 2
  D1 - (b1 + a1) / 2
  x - nodes*C1 + D1

  value - 0
  for (ii in seq_along(x)){
   tmp - 0
   for (jj in seq_along(y)){
     tmp - tmp + C1 * weights[jj] * f(x[jj], y[ii], ...)
   }
   value - value + C2 * weights[ii] * tmp
  }
  value
 }

 ## test function, the result is pi for y=1
 f - function(x, y) {
  res - 1 / (sqrt(x)*(1+x))
  c(res, res/2, 2*res)
 }

 ## Transformation rule from Numerical Recipes
 ## to deal with the [0, infty) range of x

 mixedrule - function(x, y, f, ...)
 {
  t - exp(pi*sinh(x))
  dtdx - t*(pi*cosh(x))
  f(t, y, ...)*dtdx
 }


 vAverage(mixedrule, -4, 4, 0.0, 1, 20, f) - c(pi, pi/2, 2*pi)
 ## -3.535056e-06 -1.767528e-06 -7.070112e-06


 So it seems to work. I wonder though if I may have missed an easier
 (and more reliable) way to perform such integration using base
 functions or an add-on package that I may have overlooked.

 Best regards,

 baptiste

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

 David Winsemius, MD
 West Hartford, CT



__
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] bivariate vector numerical integration with infinite range

2010-09-21 Thread baptiste auguie
Thanks, adaptIntegrate() seems perfectly suited, I'll just need to
figure a transformation rule for the infinite limit. The suggestion of
x-1/x does not seem to work here because it also transforms 0 into
-infinity. I think exp(pi* sinh(x)) could be a better choice,
according to Numerical Recipes.

Thanks,

baptiste


On 21 September 2010 14:26, Hans W Borchers hwborch...@googlemail.com wrote:
 baptiste auguie baptiste.auguie at googlemail.com writes:


 Dear list,

 I'm seeking some advice regarding a particular numerical integration I
 wish to perform.

 The integrand f takes two real arguments x and y and returns a vector
 of constant length N. The range of integration is [0, infty) for x and
 [a,b] (finite) for y. Since the integrand has values in R^N I did not
 find a built-in function to perform numerical quadrature, so I wrote
 my own after some inspiration from a post in R-help,

 The function adaptIntegral() in the 'cubature' package integrates
 multi-valued functions over n-dimensional finite hypercubes, as do the
 functions in 'R2Cuba'.
 If the hypercube is (partly) infinite, a transformation such as x -- 1/x
 per infinite axis (as in NR) has to be applied.

 For two dimensions, another approach could be to apply the integrate()
 function twice, because this 1-dimensional integration function can handle
 infinite intervals.
 Hint: First inegrate over the finite dimension(s).

 Example: Integrate sin(x)/exp(y) for 0 = x = pi, 0 = y = Inf (value: 2)
 
    f1 - function(y) 1/exp(y)
    f2 - function(x) sin(x) * integrate(f1, 0, Inf)$value
    integrate(f2, 0, pi)
    # 2 with absolute error  2.2e-14
 
 Note that the absolute error is not correct, as the first integration has
 its own error term. You have to do your own error estimation.

 Hans Werner


 [...]

 So it seems to work. I wonder though if I may have missed an easier
 (and more reliable) way to perform such integration using base
 functions or an add-on package that I may have overlooked.

 Best regards,

 baptiste



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


Re: [R] puzzle with integrate over infinite range

2010-09-21 Thread baptiste auguie
I see, thank you.

I'm still worried by the very dramatic error I obtained just from
shifting so slightly the support of the integrand, it took me a while
to figure what happened even with this basic example (I knew the
integral couldn't be so small!).

For a general integration in [0, infty), there must be a link between
the number of quadrature points, the transformation applied to the
integrand, and the region (position, width) where the measurable
integrand needs to be in order to be sampled by the quadrature. I
guess this kind of info lies deep inside the source code though.

Thanks,

baptiste



On 21 September 2010 19:00, Thomas Lumley tlum...@u.washington.edu wrote:
 On Tue, 21 Sep 2010, baptiste Auguié wrote:

 Thanks, I'll do that too from now on.
 It strikes me that in a case such as this one it may be safer to use a
 truncated, finite interval around the region where the integrand is
 non-zero, rather than following the advice of ?integrate to use Inf as
 integration limit. At least one wouldn't risk to get an entirely wrong
 result depending on a choice of rel.tol. Regarding this parameter, is there
 a simple interpretation of how it affected the result in the context of my
 example?


 Not really.

 If you know where the integrand is non-zero then you can shift it so that
 integrate() can handle it.  If you don't know then you can't get the
 truncated interval right.

 The truncation approach works well for the Normal density because it it is
 non-negative, symmetric, and has nearly bounded support. The truncation
 error goes down extremely fast and if the mode of the density is in the
 center of the interval then all the mass can easily be found.   If you have
 a function with multiple modes and heavier tails it is harder to get an
 interval that is large enough to make the truncation error small, and still
 allows the integrate() function to find all the mass.

    -thomas

 Thomas Lumley
 Professor of Biostatistics
 University of Washington, Seattle




-- 


Dr. Baptiste Auguié

Departamento de Química Física,
Universidade de Vigo,
Campus Universitario, 36310, Vigo, Spain

tel: +34 9868 18617
http://webs.uvigo.es/coloides

__
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] bivariate vector numerical integration with infinite range

2010-09-21 Thread baptiste auguie
Thanks. I am having trouble getting adaptIntegrate to work with a
multivalued integrand though, and cannot find a working example.
Anyone had better luck with it?

library(cubature)

 f - function(x, y) {
+   res - 1 / (sqrt(x)*(1+x))
+   c(res, res/2, 2*res)
+ }

 adaptIntegrate(f, lowerLimit=c(0.1, 0), upperLimit=c(10, 1), fDim = 3)
[1] adaptIntegrate: Error in evaluation function f(x) for x=
   res
[1,] 0.07355275 0.03677638 0.1471055
[2,] 0.94280904 0.47140452 1.8856181
Error in adaptIntegrate(f, lowerLimit = c(0.1, 0), upperLimit = c(10,  :
 adaptIntegrate: Result f(x) is not numeric or has wrong dimension


Best,

baptiste

On 21 September 2010 17:11, Hans W Borchers hwborch...@googlemail.com wrote:
 baptiste auguie baptiste.auguie at googlemail.com writes:


 Thanks, adaptIntegrate() seems perfectly suited, I'll just need to
 figure a transformation rule for the infinite limit. The suggestion of
 x-1/x does not seem to work here because it also transforms 0 into
 -infinity. I think exp(pi* sinh(x)) could be a better choice,
 according to Numerical Recipes.

 Yes, that's one way.
 But you can also split the integral in two parts, one from 0 to 1 and then
 from 1 to Inf. The first one is a finite hypercube and the second can be
 transformed with x -- 1/x into [0, 1].

 I usually prefer the second approach for higher-dimensional applications
 as the Jacobian appears to be simpler. In the literature you will find
 discussions on how far out the finite hypercube should reach for lowering
 the absolute error.

 Hans Werner

 Thanks,

 baptiste


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


Re: [R] bivariate vector numerical integration with infinite range

2010-09-21 Thread baptiste auguie
Got it, thanks!

baptiste

On 21 September 2010 22:38, Hans W Borchers hwborch...@googlemail.com wrote:
 baptiste auguie baptiste.auguie at googlemail.com writes:


 Thanks. I am having trouble getting adaptIntegrate to work with a
 multivalued integrand though, and cannot find a working example.
 Anyone had better luck with it?

 The function to be integrated needs a vector as input:

    f - function(x) {
        res - 1 / (sqrt(x[1])*(1+x[1]))
        c(res, res/2, 2*res)
    }

    adaptIntegrate(f, lowerLimit=c(0.1, 0), upperLimit=c(10, 1), fDim = 3)
    $integral
    [1] 1.9164832 0.9582416 3.8329665

    $error
    [1] 1.265252e-05 6.326261e-06 2.530504e-05

    $functionEvaluations
    [1] 323

   $returnCode
   [1] 0

 Hans Werner

 library(cubature)
 
  f - function(x, y) {
 +   res - 1 / (sqrt(x)*(1+x))
 +   c(res, res/2, 2*res)
 + }
 
  adaptIntegrate(f, lowerLimit=c(0.1, 0), upperLimit=c(10, 1), fDim = 3)
 [1] adaptIntegrate: Error in evaluation function f(x) for x=
            res
 [1,] 0.07355275 0.03677638 0.1471055
 [2,] 0.94280904 0.47140452 1.8856181
 Error in adaptIntegrate(f, lowerLimit = c(0.1, 0), upperLimit = c(10,  :
  adaptIntegrate: Result f(x) is not numeric or has wrong dimension

 Best,

 baptiste


 __
 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] lattice centre a diverging colour scale

2010-09-23 Thread baptiste auguie
Dear list,

I'm using lattice::levelplot to plot a coloured image of 3D data. The
range of the z values goes from negative to positive, but is not
exactly centred around 0. I would however like to map a diverging
colour scale with white falling exactly at 0, and both extremes being
symmetrical in the legend to better contrast the opposite change in
colour saturation. The following dummy example illustrates my problem,


library(lattice)
d - transform(expand.grid(x=seq(0, 10, length=100),
   y=seq(0, 10, length=100)),
   z = sin(x/pi)*cos(0.5*y/pi) - 0.2)

levelplot(z~x*y, data=d,
  panel=panel.levelplot.raster,
  cuts = 100, interpolate = TRUE)

The colour scale goes from -0.3 to 0.9 with a middle (white) value of
0.3 approximately.  I'd like it to be from -1 (most saturated blue) to
1 (most saturated pink), say, with 0 being white.

I read the entry in ?levelplot and in ?level.colors but could not find
a solution to this particular case.

Sincerely,

baptiste

__
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] boundary check

2010-09-24 Thread baptiste auguie
Hi,

I remember a discussion we had on this list a few months ago for a
better way to decide if a point is inside a convex hull. It eventually
lead to a R function in this post,

http://tolstoy.newcastle.edu.au/R/e8/help/09/12/8784.html

I don't know if it was included in the geometry package in the end.

HTH,

baptiste


On 24 September 2010 12:44, Michael Bedward michael.bedw...@gmail.com wrote:
 Hello,

 If an N-dimensional convex hull fits your idea of a smallest ball
 then you could try the convhulln function in the geometry package.

 For testing if a new point is inside a previously derived hull, one
 brute force approach is to rbind the new point to your data, generate
 a new hull and see if it is the same as the previous one.

 I've only used convhulln in low dimensions so I don't know how
 efficient it is when N is large.

 Hope this helps.
 Michael


 On 24 September 2010 19:44, Feng Li feng...@stat.su.se wrote:
 Dear R,

 I have a covariates matrix with 10 observations,  e.g.

 X - matrix(rnorm(50), 10, 5)
 X
             [,1]        [,2]        [,3]        [,4]       [,5]
  [1,]  0.24857135  0.30880745 -1.44118657  1.10229027  1.0526010
  [2,]  1.24316806  0.36275370 -0.40096866 -0.24387888 -1.5324384
  [3,] -0.33504014  0.42996246  0.03902479 -0.84778875 -2.4754644
  [4,]  0.06710229  1.01950917 -0.09325091 -0.03222811  0.4127816
  [5,] -0.13619141  1.33143821 -0.79958805  2.08274102  0.6901768
  [6,] -0.45060357  0.19348831 -1.23793647 -0.72440163  0.5057326
  [7,] -1.20740516  0.20231086  1.15584485  0.8170 -1.2719855
  [8,] -1.81166284 -0.07913113 -0.91080581 -0.34774436  0.9552182
  [9,]  0.19131383  0.14980569 -0.37458224 -0.09371273 -1.7667203
 [10,] -0.85159276 -0.66679528  1.63019340  0.56920196 -2.4049600

 And I define a boundary of X:  The smallest ball that nests all the
 observations of X. I wish to check if a particular point x_i

 x_i - matrix(rnorm(5), 1, 5)
 x_i
           [,1]      [,2]       [,3]      [,4]      [,5]
 [1,] -0.1525543 0.4606419 -0.1011011 -1.557225 -1.035694

 is inside the boundary of X or not. I know it's easy to do it with 1-D or
 2-D, but I don't knot how to manage it when the dimension is large.

 Can someone give a hint? Thanks in advance!


 Feng

 --
 Feng Li
 Department of Statistics
 Stockholm University
 106 91 Stockholm, Sweden
 http://feng.li/

        [[alternative HTML version deleted]]

 __
 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-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] Facets in ggplot2

2010-10-01 Thread baptiste auguie
Try this,

qplot(outcome, counts, data=d.AD, facets=.~ treatment)

HTH,

baptiste

__
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] Include externally generated pdf in output (without Sweave)

2010-10-03 Thread baptiste auguie
Hi,

Check the grImport package (I think it has a vignette, perhaps on Paul
Murrell's homepage.)

HTH,

baptiste



On 3 October 2010 14:52, Tal Galili tal.gal...@gmail.com wrote:
 Hello Dieter,

 Looking at this thread (from 2005)
 http://tolstoy.newcastle.edu.au/R/help/05/10/14320.html
 It seems you can't read a pdf file to R (at least then, I hope there was an
 update since).

 BUT

 You could potentially read an image file (like, for example, tiff) using
 something like
 read.picture {SoPhy}
 And then write that into the PDF you are creating in R.

 The best thing is if there was some function to read a vector file into R
 (and not only the pixel).  Maybe such a function exits, you should check.

 Either way, great question.
 Tal





 Contact
 Details:---
 Contact me: tal.gal...@gmail.com |  972-52-7275845
 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
 www.r-statistics.com (English)
 --




 On Sun, Oct 3, 2010 at 12:04 PM, Dieter Menne
 dieter.me...@menne-biomed.dewrote:

 Dear useRs,

 I generated a simple image-based report using the sequence:

 pdf()
 plot(.)
 textplot( for short texts, from gplots)
 dev.off()

 Is there an easy way to include an single pdf-page from an external file
 (not R generated).

 Note: For final reports, I know how to use Sweave, but I am looking for a
 quick solution with less overhead. Something like textplot() for pdf.


 Dieter

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


        [[alternative HTML version deleted]]

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


Re: [R] Plot table as table

2010-10-13 Thread baptiste auguie
Hi,

grid.table in gridExtra might give you some inspiration.

HTH,

baptiste

On 13 October 2010 10:14, Joel joda2...@student.uu.se wrote:

 It should look something like this (not at all relevant except the look)

 http://r.789695.n4.nabble.com/file/n2993297/tableR19.jpg
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Plot-table-as-table-tp2993270p2993297.html
 Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] overwritten plots in pdf file

2009-09-29 Thread baptiste auguie
Hi,

Try opening and closing the device outside the loop,


pdf(D:/research/plot.pdf)

for (i in 1:n) {
plot(mon, mu, type ='o')
}

dev.off()

HTH,

baptiste

__
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] Macro variable substitution

2009-09-29 Thread baptiste auguie
Hi,

I guess you want ?assign

See also this page for a working example,

http://wiki.r-project.org/rwiki/doku.php?id=guides:assigning-variable-names

HTH,

baptiste

2009/9/29 David Young dyo...@telefonica.net:
 Hello All,

 I'm a new R user and have a question about what in SAS would be called
 macro variable substitution.  Below is some R code that doesn't work,
 but I think it will illustrate what I'd like to do.

 readfunc-function(x) {
  x - read.table(paste(x,.csv,sep=), header=TRUE,sep=,)
 }
 readfunc(TEF)

 What I'd like to do is have the letters TEF become the name of the new
 R data and also be used in conjunction with .csv to read the file
 TEF.csv.

 So working R code looks like this:

 TEF - read.table(TEF.csv, header=TRUE,sep=,)

 but I'd like to type the changing letter sequence just once.

 Any suggestions would be appreciated.

 --
 Best regards,

 David Young
 Marketing and Statistical Consultant
 Madrid, Spain
 +34 913 540 381
 http://www.linkedin.com/in/europedavidyoung

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


Re: [R] lattice: How to display no box but only a y-axis on the left + Thicker lines

2009-09-30 Thread baptiste auguie
2009/9/30 lith minil...@gmail.com:
 Yes. You can get back the tick marks with scaless$col:

 Thanks for the hint. May I kindly ask what would be the easiest way to
 draw a line on the left side?

Try this,

mpanel = function(...) { grid.segments(0,0,0,1) ; panel.bwplot(...) }

bwplot(y~x, data=data.frame(y=rnorm(10),x=sample(letters[1:3],10,repl=T)),
 par.settings=list(axis.line=list(col=NA)), scales = list(col =
1), panel=mpanel)


HTH,

baptiste



 Thanks,
 Tom

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


Re: [R] dichromat, regexp, and grid objects

2009-09-30 Thread baptiste auguie
Replying to myself here,

Hadley pointed out this website on the ggplot2 mailing list,

http://colororacle.cartography.ch/

And this seems like a more straight-forward solution to my query
(albeit not using R). It sort of makes sense to momentarily alter the
computer display rather than parse the code for colour and fill
regular expressions...

baptiste


2009/9/28 baptiste auguie baptiste.aug...@googlemail.com:
 Dear list,

 The dichromat package defines a dichromat function which Collapses
 red-green color distinctions to approximate the effect of the two
 common forms of red-green colour blindness, protanopia and
 deuteranopia.

 library(dichromat)
 library(grid)

 colorStrip -
  function (colors = 1:3, draw = TRUE)
 {
  x - seq(0, 1 - 1/length(colors), length = length(colors))
  y - rep(0.5, length(colors))
  my.grob - grid.rect(x = unit(x, npc), y = unit(y, npc),
                       width = unit(1/length(colors), npc),
                       height = unit(1, npc), just = left, hjust =
 NULL, vjust = NULL,
                       default.units = npc, name = NULL,
                       gp = gpar(fill = colors, col = colors, draw =
 draw, vp = NULL))
  my.grob
 }
 colorStrip(1:3)
 colorStrip(dichromat(1:3))

 Now what would be nice is a function that can edit the colours  (col
 and fill parameters) of an existing grob.

 dichromatit - function(x){
  .NotYetImplemented()
 }

 dichromatit(colorStrip())

 It could allow high-level testing for visual perception of lattice and
 ggplot2 plots,

 p1 = xyplot(1~1)
 p2 = qplot(1,1, colour= I(red))

 dichromatit(p1)
 p2 + dichromatit()


 One approach could be to use only integer codes for colours, and
 modify the current palette() (works also for base graphics). But this
 is quite a stringent request for lattice and ggplot2 which define many
 named colours in their various themes and scales. Therefore I'd like
 to think of an approach based on a recursive modification of a grob's
 gpar components. Does this seem doable with some regular expression
 magic [*]?

 All the best,

 baptiste




 [*]: http://xkcd.com/208/


__
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] A point in a vector?

2009-09-30 Thread baptiste auguie
Hi,

assuming v is sorted, try this,

v[ findInterval(x,v)+0:1 ]

see ?findInterval and perhaps ?cut

HTH,

baptiste



2009/9/30 Corrado ct...@york.ac.uk:
 Dear list,

 I have a strange requirement  I have a vector, for example v-
 c(0,0,0,0,1,2,4,6,8,8,8,8). I have a value,for example x- 4.8.

 I would like to understand in which sub interval of v is x. In this case, v
 would be in the sub interval [4,6] that is in the subinterval starting from
 element j=7 to the element j+1=8.

 Can we do that with an R command?

 Regards
 --
 Corrado Topi

 Global Climate Change  Biodiversity Indicators
 Area 18,Department of Biology
 University of York, York, YO10 5YW, UK
 Phone: + 44 (0) 1904 328645, E-mail: ct...@york.ac.uk

 __
 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] pass ... to multiple sub-functions

2009-10-01 Thread baptiste auguie
Dear list,

I know I have seen this discussed before but I haven't been successful
in searching for ellipsis, dots, ... in the archives. I would
like to filter ... arguments according to their name, and dispatch
them to two sub-functions, say fun1 and fun2. I looked at lm() but it
seemed more complicated than I need as it modifies the calling
function among other things. What is the best approach for this? My
current version presented below seems very awkward.

Best regards,

baptiste

sessionInfo()
R version 2.9.2 (2009-08-24)
i386-apple-darwin8.11.1

fun1 - function(col, row){
  print(col)
  print(row)
}

fun2 - function(x){
  print(x)
}

foo - function(..., lty=1){

  dots - list(...)

  cl - match.call()

  col - eval.parent(cl$col)
  row - eval.parent(cl$row)

  params.fun1 -  c(col, row)

  removed - na.omit(match(names(cl), params.fun1))
  # index whichever arguments were passed to fun1

  fun1(col, row)

  fun2(dots[seq_along(dots)[-removed]])

}

foo()
foo(col=1)
foo(col=1, row=1, g=2, test = abc)

__
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] pass ... to multiple sub-functions

2009-10-01 Thread baptiste auguie
2009/10/1 Peter Ruckdeschel peter.ruckdesc...@web.de:


   removed - c(lty,params.fun1)
   ## I assume you do not want to pass on argument lty...
   dots.remaining - cl[-1] ### remove the function name
   dots.remaining - dots.remaining[! names(dots.remaining)
 %in% removed]

 Best, Peter



Thank you, that's very helpful.

I vaguely remember there was also a package to deal with this problem
(among other things). Have I dreamed that?

Best,

baptiste

__
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] Looking for a better way to document my packages

2009-10-01 Thread baptiste auguie
Hi,

I know of three options that resemble your query,

- the roxygen package

- a ruby script called weeder by Hadley Wikham

- the inlinedocs package on r-forge

I only ever used roxygen though, so i can't speak for the relative
merits of the others.

HTH,

baptiste


2009/10/1 Steve Lianoglou mailinglist.honey...@gmail.com:
 Hi all,

 Trying to do what my subject says.

 As I'm trying to be better about making packages out of my code, I'd like
 the packages themselves to be better, which means *.Rd-documenting my code.
 The thing is, from years of programming other languages prior to landing in
 the R pond, I've grown accustomed to documenting my functions inline. I'm
 not just used to it, but I like it more than having function documentation
 completely removed from my function, code.

 So, for example

 myNeatFunction - function(arg1, arg2, arg3=NULL, ...) {
  # One liner describing the neat thing this function does.
  #
  # More comments, probably very much what would be in the
  # \description section of the *Rd
  #
  # Parameters
  # --
  # arg1 : some comments
  # arg2 : some comments
  # ... This is essentially the same exact stuff that would
  # be in the \arguments{} section of the *.Rd
  #
  # Returns
  # ---
  # A description of what's returned, let's say this is
  # what you'd find in the \value{} section.
  #
  # Notes
  # -
  # Maybe something like the \details{} section, though this
  # might as well be up in the description section, too.
  # etc.
 }

 There's essentially a 1-to-1 mapping of the comments I write here and what I
 would write in an *.Rd file, but I'd rather have it written in my function
 definition than an external document.

 Are there any tools that help facilitate this? Or are there better ways you
 folks have figured out to do something similar?

 I don't need the function comment block to be exactly what I showed here,
 but it's just an example of how I'm currently writing my stuff. I'm thinking
 something like sphinx (http://sphinx.pocoo.org/) from the python world would
 be cool. Perhaps there's a way to make a plugin for that to parse R-code.
 That's more work than I want to bit off right now, but if there isn't
 something useful in R-land already, it might be a fun side project.

 Just curious,
 -steve

 --
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  |  Memorial Sloan-Kettering Cancer Center
  |  Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact

 __
 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] inverse currying

2009-10-01 Thread baptiste auguie
Dear list,

I have the following function,

sugar = function(fun, id = id){
  ff - formals(fun)
  if( id %in% names(ff))
stop(id is part of args(fun))
  formals(fun) - c(unlist(ff), alist(id=))
  fun
}

which one may use on a function foo,

foo = function(x){
  x
}

sugar(foo) # results in the extended closure,

function (x, id)
{
x
}

Its limitation (other than not working with .Primitives) is the 'id'
tag that I add in the formals of fun(). I don't know how to create a
alist(id=) pairlist where id can be changed. I tried the usual bquote
and substitute approach but they don't seem to work here. I suppose I
could do something like,

parse(text = paste(alist(,id, =), sep=))

but this is usually not recommended.

Any ideas?

Best regards,

baptiste

__
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] plot ᵒ C in graph axis label

2009-10-02 Thread baptiste auguie
Hi,

You cannot start with a * in expression(). Try this,

 plot(x~y,ylab=expression(~degree~C))

or even, as a short-cut,

 plot(x~y,ylab=~degree~C)

HTH,

baptiste

2009/10/2 e-letter inp...@gmail.com:
 Readers,

 I have tried to use a plotmath command to add the temperature degree
 sign (i.e. ᵒ C) to the axis label of a graph:

 x-(1:10)
 y-(200:191)
 plot(x~y,ylab=expression(*degree~C))
 Error: syntax error, unexpected '*', expecting ',' in
 plot(x~y,ylab=expression(*

 According to plotmath manual, the syntax is '*degree' and I am able to
 use this command when a number precedes the asterisk (e.g.
 ylab=expression(0*degree~C)). But I want to omit the need for a number
 before the degree sign. Any advice please?

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


Re: [R] plot scale

2009-10-02 Thread baptiste auguie
Hi,

It looks like lattice or ggplot2 might make this easier, but I'm not
entirely sure I understood the problem, short of an example.

Best,

baptiste

2009/10/2 Duncan Murdoch murd...@stats.uwo.ca:
 On 02/10/2009 4:07 AM, Ben Kenward wrote:

 Hi,

 Is there a way to set the scale of a plot (i.e. number of axis units
 per centimeter) when you output it to postscript? If not, how am I
 supposed to plot graphs with different axis limits to the same scale?
 They just get resized to fit the paper so that graphs which show a
 smaller number of axis units end up with a larger scale.

 I don't think there's a simple way to specify the exact relationship, but
 you can do it with some work.

 When you open the postscript device, you can specify the size.  When you do
 a plot, you can specify the size of the margins, so that lets you indirectly
 specify the size of the plot region.  And of course you can specify the axis
 limits.

 So the way I'd do what you want is as follows:  plot the data, use
 par(usr) to extract the axis limits, use par(mai) to extract the margin
 size.  Then calculate the size you want for the particular scaling, and open
 the postscript device with that size, reset par(mai) to the previous
 value, and repeat your plot.

 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.


Re: [R] plot subscript text and percentage symbol in graph label axis

2009-10-02 Thread baptiste auguie
try this,

plot(x~y,ylab=expression(~degree~C),xlab=expression(x[2]~%))


baptiste

2009/10/2 e-letter inp...@gmail.com:
 Readers,

 I am unable to plot a label consisting of both subscript text and
 percentage (%) symbol:

 x-(1:10)
 y-(200:191)
 plot(x~y,ylab=expression(~degree~C),xlab=expression(x[2]~%))
 Error: syntax error, unexpected ERROR in
 plot(x~y,ylab=expression(~degree~C),xlab=expression(x~%)

 It seems that % is a special character in R? I have looked in the
 introductory manual but can see no reference to reserved characters.

 Yours,

 rhelpatconference.jabber.org
 r251
 mandriva2008

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


Re: [R] inverse currying

2009-10-02 Thread baptiste auguie
After some more digging (grep alist R-devel/ ), I've come up with this,

tools:::as.alist.symbol(x)

sugar = function(fun, id = id){
 ff - formals(fun)
 if( id %in% names(ff))
   stop(paste(id, is part of args(fun)))

 new.arg - tools:::as.alist.symbol(id)

 formals(fun) - c(unlist(ff), new.arg)
 fun

}

foo = function(x, a=1){
 x
}

sugar(foo)
sugar(foo, 'a')
sugar(sugar(foo))

sugar(foo, 'my.new.arg')


Best,

baptiste



2009/10/1 baptiste auguie baptiste.aug...@googlemail.com:
 Dear list,

 I have the following function,

 sugar = function(fun, id = id){
  ff - formals(fun)
  if( id %in% names(ff))
    stop(id is part of args(fun))
  formals(fun) - c(unlist(ff), alist(id=))
  fun
 }

 which one may use on a function foo,

 foo = function(x){
  x
 }

 sugar(foo) # results in the extended closure,

 function (x, id)
 {
    x
 }

 Its limitation (other than not working with .Primitives) is the 'id'
 tag that I add in the formals of fun(). I don't know how to create a
 alist(id=) pairlist where id can be changed. I tried the usual bquote
 and substitute approach but they don't seem to work here. I suppose I
 could do something like,

 parse(text = paste(alist(,id, =), sep=))

 but this is usually not recommended.

 Any ideas?

 Best regards,

 baptiste


__
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] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread baptiste auguie
Hi,

Try this,

dev.new()
layout(matrix(1:4,2, by=T))

plot(1:10,main=top left plot)
plot(1:10,main=top right plot)
plot(1:10,main=bottom left plot)
plot(1:10,main=bottom right plot)

for (ii in 1:2){
for (jj in 1:2){
par(mfg=c(ii,jj))
text(5,2, lab=paste(plot #:,ii,,,jj,sep=))
}
}
par(mfg=c(1,1))
lines(c(3:7,7:3),col=red)

HTH,

baptiste
2009/10/4 Marianne Promberger marianne.promber...@kcl.ac.uk:
 Thanks for the quick reply. However ...

 David Winsemius dwinsem...@comcast.net 03-Oct-09 20:50:
 MP layout(matrix(c(1,2),1))
 MP plot(1:10,main=left plot)
 MP plot(10:1,main=right plot)
 MP lines(c(3:7,7:3),col=red)
 MP
 MP but of course now lines() gets added to the right plot. I
 MP
 MP Is there any way to make the lines() go to the fist plot (left
 MP plot)?

 If you look at layout's help page there appears to be a worked example
 of an even more complex task. The answer appears to be assingning
 numbers to regions and then inserting par(mar=  with an appropriately
 constructed destination arguments prior to each added piece.

 Sorry, but I fail to find the solution in the page returned by
 ?layout, assuming that's what you mean.

 Yes, the numbers in the matrix given to layout() give the order of
 where plots will be put, so

 layout(matrix(c(2,1),1))

 then

 plot(1:10,main=left plot)
 plot(10:1,main=right plot)
 lines(c(3:7,7:3),col=red)

 puts left plot on the right hand side and right plot on the
 left. But the lines() still go to the right plot plot (now on the
 left hand side) which gets called last.

 The par(mar ... of the scatterplot with marginal histograms example
 just set the margins of the histogram plots, then they get plotted to
 the region with the next number given in the layout() matrix.

 Maybe I'm missing something.

 Thanks,

 Marianne


 --
 David

 On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:

 Dear R users,

 I create a graphic with two plots side by side using layout(), like
 this:

 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 lines(c(3:7,7:3),col=red)
 plot(10:1,main=right plot)

 The lines() obivously get added to the left plot plot.

 Now, I'm trying to write a function that builds up a plot bit by bit
 to
 then include it in a LaTeX presentation with overlays. I'm using
 dev.copy(), and it would make my life much easier (because in fact I
 call all sorts of additional axis() etc after plot) if I could call
 the above commands in this order:

 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 plot(10:1,main=right plot)
 lines(c(3:7,7:3),col=red)

 but of course now lines() gets added to the right plot. I

 Is there any way to make the lines() go to the fist plot (left
 plot)?

 Marianne


 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

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

 --
 Marianne Promberger PhD, King's College London
 http://promberger.info
 R version 2.9.2 (2009-08-24)
 Ubuntu 9.04

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


Re: [R] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-04 Thread baptiste auguie
After some checking, I think the documentation is at best misleading
on this particular query. Nowhere could I find mention that par(mfg)
can work with layout. Instead, I found a warning that suggests
incompatibility (since mpg is explicitly tied to mfrow in ?par and
layout is said incompatible with par(mfrow)).


Relevant bits from ?par:
mfcol, mfrow
Consider the alternatives, layout and split.screen.

mfg
A numerical vector of the form c(i, j) where i and j indicate which
figure in an array of figures is to be drawn next (if setting) or is
being drawn (if enquiring). The array must already have been set by
mfcol or mfrow.

From ?layout,

Warnings
These functions are totally incompatible with the other mechanisms for
arranging plots on a device: par(mfrow), par(mfcol) and split.screen.

See Also
par with arguments mfrow, mfcol, or mfg.


I suggest the following changes,

in ?layout, section Details: The user can navigate to a given cell
using the the mpg parameter (see ?par).

in ?par, parameter mpg: The array must already have been set by
either mfcol, mfrow, or layout.

It may be that I missed an important incompatibility in complicated
layouts, but it seems to work at least for simple ones.

Best regards,

baptiste





2009/10/4 baptiste auguie baptiste.aug...@googlemail.com:
 Hi,

 Try this,

 dev.new()
 layout(matrix(1:4,2, by=T))

 plot(1:10,main=top left plot)
 plot(1:10,main=top right plot)
 plot(1:10,main=bottom left plot)
 plot(1:10,main=bottom right plot)

 for (ii in 1:2){
 for (jj in 1:2){
 par(mfg=c(ii,jj))
 text(5,2, lab=paste(plot #:,ii,,,jj,sep=))
 }
 }
 par(mfg=c(1,1))
 lines(c(3:7,7:3),col=red)

 HTH,

 baptiste
 2009/10/4 Marianne Promberger marianne.promber...@kcl.ac.uk:
 Thanks for the quick reply. However ...

 David Winsemius dwinsem...@comcast.net 03-Oct-09 20:50:
 MP layout(matrix(c(1,2),1))
 MP plot(1:10,main=left plot)
 MP plot(10:1,main=right plot)
 MP lines(c(3:7,7:3),col=red)
 MP
 MP but of course now lines() gets added to the right plot. I
 MP
 MP Is there any way to make the lines() go to the fist plot (left
 MP plot)?

 If you look at layout's help page there appears to be a worked example
 of an even more complex task. The answer appears to be assingning
 numbers to regions and then inserting par(mar=  with an appropriately
 constructed destination arguments prior to each added piece.

 Sorry, but I fail to find the solution in the page returned by
 ?layout, assuming that's what you mean.

 Yes, the numbers in the matrix given to layout() give the order of
 where plots will be put, so

 layout(matrix(c(2,1),1))

 then

 plot(1:10,main=left plot)
 plot(10:1,main=right plot)
 lines(c(3:7,7:3),col=red)

 puts left plot on the right hand side and right plot on the
 left. But the lines() still go to the right plot plot (now on the
 left hand side) which gets called last.

 The par(mar ... of the scatterplot with marginal histograms example
 just set the margins of the histogram plots, then they get plotted to
 the region with the next number given in the layout() matrix.

 Maybe I'm missing something.

 Thanks,

 Marianne


 --
 David

 On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:

 Dear R users,

 I create a graphic with two plots side by side using layout(), like
 this:

 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 lines(c(3:7,7:3),col=red)
 plot(10:1,main=right plot)

 The lines() obivously get added to the left plot plot.

 Now, I'm trying to write a function that builds up a plot bit by bit
 to
 then include it in a LaTeX presentation with overlays. I'm using
 dev.copy(), and it would make my life much easier (because in fact I
 call all sorts of additional axis() etc after plot) if I could call
 the above commands in this order:

 layout(matrix(c(1,2),1))
 plot(1:10,main=left plot)
 plot(10:1,main=right plot)
 lines(c(3:7,7:3),col=red)

 but of course now lines() gets added to the right plot. I

 Is there any way to make the lines() go to the fist plot (left
 plot)?

 Marianne


 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

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

 --
 Marianne Promberger PhD, King's College London
 http://promberger.info
 R version 2.9.2 (2009-08-24)
 Ubuntu 9.04

 __
 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

Re: [R] ggplot2: proper use of facet_grid inside a function

2009-10-05 Thread baptiste auguie
Hi,

Whether or not what follows is to be recommended I don't know, but it
seems to work,

p - ggplot(diamonds, aes(carat, ..density..)) +
  geom_histogram(binwidth = 0.2)

x = quote(cut)
facets = facet_grid(as.formula(bquote(.~.(x
p + facets

HTH,

baptiste

2009/10/5 Bryan Hanson han...@depauw.edu:
 Thanks Thierry for the work-around.  I was out of ideas.

 I had looked around for the facet_grid() analog of aes_string(), and
 concluded there wasn't one.  The only thing I found was the notion of

 facet_grid(...) but apparently it is intended for some other use, as it
 doesn't work as I thought it would (like a hypothetical
 facet_grid_string()).

 Thanks so much.  Bryan


 On 10/5/09 4:12 AM, ONKELINX, Thierry thierry.onkel...@inbo.be wrote:

 Dear Bryan,

 In the ggplot() function you can choose between aes() and aes_string().
 In the first you need to hardwire the variable names, in the latter you
 can use objects which contain the variable names. So in your case you
 need aes_string().

 Unfortunatly, facet_grid() works like aes() and not like aes_string().
 That is why you are getting errors.

 A workaround would be to add a dummy column to your data.

 library(ggplot2)
 data - mpg
 fac1 - cty
 fac2 - drv
 res - displ
 data$dummy - data[, fac2]
 ggplot(data, aes_string(x = fac1, y = res)) + geom_point() +
 facet_grid(.~dummy)

 HTH,

 Thierry


 
 
 ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Research Institute for Nature
 and Forest
 Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
 methodology and quality assurance
 Gaverstraat 4
 9500 Geraardsbergen
 Belgium
 tel. + 32 54/436 185
 thierry.onkel...@inbo.be
 www.inbo.be

 To call in the statistician after the experiment is done may be no more
 than asking him to perform a post-mortem examination: he may be able to
 say what the experiment died of.
 ~ Sir Ronald Aylmer Fisher

 The plural of anecdote is not data.
 ~ Roger Brinner

 The combination of some data and an aching desire for an answer does not
 ensure that a reasonable answer can be extracted from a given body of
 data.
 ~ John Tukey

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Namens Bryan Hanson
 Verzonden: vrijdag 2 oktober 2009 17:21
 Aan: R Help
 Onderwerp: [R] ggplot2: proper use of facet_grid inside a function

 Hello Again R Folk:

 I have found items about this in the archives, but I'm still not getting
 it right.  I want to use ggplot2 with facet_grid inside a function with
 user specified variables, for instance:

     p - ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~
 fac2)

 Where data, fac1, fac2 and res are arguments to the function.  I have
 tried

     p - ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~
 as.name(fac2))

 and

     p - ggplot(data, aes_string(x = fac1, y = res)) + facet_grid(. ~
 fac2)

 But all of these produce the same error:

 Error in `[.data.frame`(plot$data, , setdiff(cond, names(df)), drop =
 FALSE) :
   undefined columns selected

 If I hardwire the true identity of fac2 into the function, it works as
 desired, so I know this is a problem of connecting the name with the
 proper value.

 I'm up to date on everything:

 R version 2.9.2 (2009-08-24)
 i386-apple-darwin8.11.1

 locale:
 en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] grid      datasets  tools     utils     stats     graphics
 grDevices methods
 [9] base

 other attached packages:
  [1] Hmisc_3.6-0        ggplot2_0.8.3      reshape_0.8.3
 proto_0.3-8
  [5] mvbutils_2.2.0     ChemoSpec_1.1      lattice_0.17-25
 mvoutlier_1.4
  [9] plyr_0.1.8         RColorBrewer_1.0-2 chemometrics_0.4   som_0.3-4

 [13] robustbase_0.4-5   rpart_3.1-45       pls_2.1-0          pcaPP_1.7

 [17] mvtnorm_0.9-7      nnet_7.2-48        mclust_3.2
 MASS_7.2-48
 [21] lars_0.9-7         e1071_1.5-19       class_7.2-48

 loaded via a namespace (and not attached):
 [1] cluster_1.12.0

 Thanks for any help!  Bryan
 *
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University, Greencastle IN USA

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

 Druk dit bericht a.u.b. niet onnodig af.
 Please do not print this message unnecessarily.

 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
 en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd
 is
 door een geldig ondertekend document. The views expressed in  this message
 and any annex are purely those of the writer and may not be regarded as
 stating
 an official position of INBO, as long as the message is not confirmed by a
 duly
 

Re: [R] ggplot2: proper use of facet_grid inside a function

2009-10-05 Thread baptiste auguie
Now why do I always come up with a twisted bquote() where a simple
paste() would do!

Thanks,

baptiste


2009/10/5 hadley wickham h.wick...@gmail.com:
 Whether or not what follows is to be recommended I don't know, but it
 seems to work,

 p - ggplot(diamonds, aes(carat, ..density..)) +
  geom_histogram(binwidth = 0.2)

 x = quote(cut)
 facets = facet_grid(as.formula(bquote(.~.(x
 p + facets

 That's what I'd recommend.  You can also just do

 facets - facet_grid(paste(. ~ , var))

 Hadley
 --
 http://had.co.nz/


__
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] italics help in plot

2009-10-06 Thread baptiste auguie
Hi,

Try this,

 x= my title
 plot(1,1, main = bquote(italic(.(x

HTH,

baptiste

2009/10/6 Jacob Kasper jacobkas...@gmail.com:
 Part of my script reads:

 speciesName - names(data)[i]
 plot(year,depth, xlab=Year,
 ylab=Depth(m),main=expression(italic(paste(speciesName))) )

 Unfortunately, this just plots *speciesName *on my graph, not the name of
 the species in italics. Any suggestions on how to resolve this?

 Thank you
 Jacob

        [[alternative HTML version deleted]]

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


Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread baptiste auguie
Hi,

I may be missing an important design decision, but could you not have
only a single data.frame as an argument of your function? From your
example, it seems that the colour can be mapped to the fac1 variable
of data,

compareCats - function(data) {

   require(ggplot2)
   p - ggplot(data, aes(fac1, res, color=fac1)) + facet_grid(. ~ fac2)
   jit - position_jitter(width = 0.1)
   p - p + layer(geom = jitter, position = jit) +
 scale_colour_manual(values=c(red, blue))
   print(p)
   }


test - data.frame(res = rnorm(100), fac1 = as.factor(rep(c(A, B), 50)),
   fac2 = as.factor(rep(c(lrg, lrg, sm, sm), 25)))

compareCats(data = test)

rem - runif(5, 1, 100) # randomly remove a few points here and there
last_plot() %+% test[-rem,] # replot with new dataset


HTH,

baptiste



2009/10/6 Bryan Hanson han...@depauw.edu:
 Hello Again...  I¹m making a faceted plot of a response on two categorical
 variables using ggplot2 and having troubles with the coloring. Here is a
 sample that produces the desired plot:

 compareCats - function(data, res, fac1, fac2, colors) {

    require(ggplot2)
    p - ggplot(data, aes(fac1, res)) + facet_grid(. ~ fac2)
    jit - position_jitter(width = 0.1)
    p - p + layer(geom = jitter, position = jit, color = colors)
    print(p)
    }

 test - data.frame(res = rnorm(100), fac1 = as.factor(rep(c(A, B), 50)),
    fac2 = as.factor(rep(c(lrg, lrg, sm, sm), 25)))

 compareCats(data = test, res = res, fac1 = fac1, fac2 = fac2, colors =
 c(red, blue))

 Now, if I get away from idealized data where there are the same number of
 data points per group (25 in this case), I run into problems.  So, if you
 do:

 rem - runif(5, 1, 100) # randomly remove a few points here and there
 test - test[-rem,]
 compareCats(data = test, res = res, fac1 = fac1, fac2 = fac2, colors =
 c(red, blue))

 R throws an error due to mismatch between the recycling of colors and the
 actual number of data points:

 Error in `[-.data.frame`(`*tmp*`, gp, value = list(colour = c(red,  :
  replacement element 1 has 2 rows, need 47

 I'm new to ggplot2, but have been through the book and the web site enough
 to know that my problem is mapping the varible to the aesthetic; I also
 know I can either map or set the colors.

 The question, finally:  is there an simple/elegant way to map a list of two
 colors corresponding to A and B onto any random sample size of A and B with
 faceting?  If not, and I must set the colors:  Do I compute the length of
 all possible combos of A, B with lrg, sm, and then create one long vector of
 colors for the entire plot?  I tried something like this, and was not
 successful, but perhaps could be with more work.

 All advice appreciated, Bryan (session info below)

 *
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University, Greencastle IN USA

 sessionInfo()
 R version 2.9.2 (2009-08-24)
 i386-apple-darwin8.11.1

 locale:
 en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] grid      datasets  tools     utils     stats     graphics  grDevices
 methods
 [9] base

 other attached packages:
  [1] ggplot2_0.8.3      reshape_0.8.3      proto_0.3-8        mvbutils_2.2.0
  [5] ChemoSpec_1.1      lattice_0.17-25    mvoutlier_1.4      plyr_0.1.8
  [9] RColorBrewer_1.0-2 chemometrics_0.4   som_0.3-4
 robustbase_0.4-5
 [13] rpart_3.1-45       pls_2.1-0          pcaPP_1.7          mvtnorm_0.9-7
 [17] nnet_7.2-48        mclust_3.2         MASS_7.2-48        lars_0.9-7
 [21] e1071_1.5-19       class_7.2-48

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


Re: [R] ggplot2: mapping categorical variable to color aesthetic with faceting

2009-10-06 Thread baptiste auguie
Further to my previous reply, it occurred to me that ggplot2 would
only ever use data and colors in your calls to compareCats(): res =
res, fac1 = fac1, fac2 = fac2 have no effect whatsoever.

If you want the user to be able to specify the variables used in the
ggplot2 call, you probably want to look at ?aes_string, as shown
below,

compareCats - function(data, fac1=fac1, fac2=fac2, res=res,
colors=c(red, blue)) {

  require(ggplot2)
  p - ggplot(data, aes_string(x=fac1, y=res, color=fac1)) +
facet_grid(paste(. ~ , fac2))
  jit - position_jitter(width = 0.1)
  p - p + layer(geom = jitter, position = jit) +
scale_colour_manual(values=colors)
  print(p)
  }

test - data.frame(res = rnorm(100), fac1 = as.factor(rep(c(A, B), 50)),
  fac2 = as.factor(rep(c(lrg, lrg, sm, sm), 25)))

compareCats(data = test)

rem - sample(10, 1:ncol(test)) # randomly remove a few points here and there
last_plot() %+% test[-rem, ] # replot with new dataset

HTH,

baptiste




2009/10/6 baptiste auguie baptiste.aug...@googlemail.com:
 Hi,

 I may be missing an important design decision, but could you not have
 only a single data.frame as an argument of your function? From your
 example, it seems that the colour can be mapped to the fac1 variable
 of data,

 compareCats - function(data) {

   require(ggplot2)
   p - ggplot(data, aes(fac1, res, color=fac1)) + facet_grid(. ~ fac2)
   jit - position_jitter(width = 0.1)
   p - p + layer(geom = jitter, position = jit) +
     scale_colour_manual(values=c(red, blue))
   print(p)
   }


 test - data.frame(res = rnorm(100), fac1 = as.factor(rep(c(A, B), 50)),
   fac2 = as.factor(rep(c(lrg, lrg, sm, sm), 25)))

 compareCats(data = test)

 rem - runif(5, 1, 100) # randomly remove a few points here and there
 last_plot() %+% test[-rem,] # replot with new dataset


 HTH,

 baptiste



 2009/10/6 Bryan Hanson han...@depauw.edu:
 Hello Again...  I¹m making a faceted plot of a response on two categorical
 variables using ggplot2 and having troubles with the coloring. Here is a
 sample that produces the desired plot:

 compareCats - function(data, res, fac1, fac2, colors) {

    require(ggplot2)
    p - ggplot(data, aes(fac1, res)) + facet_grid(. ~ fac2)
    jit - position_jitter(width = 0.1)
    p - p + layer(geom = jitter, position = jit, color = colors)
    print(p)
    }

 test - data.frame(res = rnorm(100), fac1 = as.factor(rep(c(A, B), 50)),
    fac2 = as.factor(rep(c(lrg, lrg, sm, sm), 25)))

 compareCats(data = test, res = res, fac1 = fac1, fac2 = fac2, colors =
 c(red, blue))

 Now, if I get away from idealized data where there are the same number of
 data points per group (25 in this case), I run into problems.  So, if you
 do:

 rem - runif(5, 1, 100) # randomly remove a few points here and there
 test - test[-rem,]
 compareCats(data = test, res = res, fac1 = fac1, fac2 = fac2, colors =
 c(red, blue))

 R throws an error due to mismatch between the recycling of colors and the
 actual number of data points:

 Error in `[-.data.frame`(`*tmp*`, gp, value = list(colour = c(red,  :
  replacement element 1 has 2 rows, need 47

 I'm new to ggplot2, but have been through the book and the web site enough
 to know that my problem is mapping the varible to the aesthetic; I also
 know I can either map or set the colors.

 The question, finally:  is there an simple/elegant way to map a list of two
 colors corresponding to A and B onto any random sample size of A and B with
 faceting?  If not, and I must set the colors:  Do I compute the length of
 all possible combos of A, B with lrg, sm, and then create one long vector of
 colors for the entire plot?  I tried something like this, and was not
 successful, but perhaps could be with more work.

 All advice appreciated, Bryan (session info below)

 *
 Bryan Hanson
 Professor of Chemistry  Biochemistry
 DePauw University, Greencastle IN USA

 sessionInfo()
 R version 2.9.2 (2009-08-24)
 i386-apple-darwin8.11.1

 locale:
 en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

 attached base packages:
 [1] grid      datasets  tools     utils     stats     graphics  grDevices
 methods
 [9] base

 other attached packages:
  [1] ggplot2_0.8.3      reshape_0.8.3      proto_0.3-8        mvbutils_2.2.0
  [5] ChemoSpec_1.1      lattice_0.17-25    mvoutlier_1.4      plyr_0.1.8
  [9] RColorBrewer_1.0-2 chemometrics_0.4   som_0.3-4
 robustbase_0.4-5
 [13] rpart_3.1-45       pls_2.1-0          pcaPP_1.7          mvtnorm_0.9-7
 [17] nnet_7.2-48        mclust_3.2         MASS_7.2-48        lars_0.9-7
 [21] e1071_1.5-19       class_7.2-48

 __
 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

Re: [R] ggplot equivalent of par(xaxt)

2009-10-06 Thread baptiste auguie
Hi,

2009/10/6 John Kane jrkrid...@yahoo.ca:
 How do I suppress the numbers on the x-axis?


Try this,

p + opts(axis.text.x = theme_blank())

HTH,

baptiste



 Thanks


      __
 [[elided Yahoo spam]]

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


Re: [R] ggplot equivalent of par(xaxt)

2009-10-06 Thread baptiste auguie
body(theme_grey)

could help you find the name of a particular option (that's what I did).

baptiste

2009/10/6 John Kane jrkrid...@yahoo.ca:
 Lovely.  I knew it was not that difficult, I had even gotten as far as 
 deciding it had to be an opts() command but I had no idea of what it was.

 Thanks very much.



 --- On Tue, 10/6/09, baptiste auguie baptiste.aug...@googlemail.com wrote:

 From: baptiste auguie baptiste.aug...@googlemail.com
 Subject: Re: [R] ggplot equivalent of par(xaxt)
 To: John Kane jrkrid...@yahoo.ca
 Cc: R R-help r-h...@stat.math.ethz.ch
 Received: Tuesday, October 6, 2009, 2:57 PM
 Hi,

 2009/10/6 John Kane jrkrid...@yahoo.ca:
  How do I suppress the numbers on the x-axis?
 

 Try this,

 p + opts(axis.text.x = theme_blank())

 HTH,

 baptiste



  Thanks
 
 
 
  __
  [[elided Yahoo spam]]
 
  __
  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.
 



      __
 Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your 
 favourite sites. Download it now
 http://ca.toolbar.yahoo.com.


__
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] two plots on the same axis

2009-10-07 Thread baptiste auguie
Hi,

Your two data sets have a different year so I'm not sure what you want
to do with the x axis.

The code below plots both data sets on the same graph, with a range of
two years,


d1 - read.table(~/Downloads/2005.txt)
d2 - read.table(~/Downloads/2006.txt)


cleanup - function(d){
  names(d) - c(year, month, day, value)
  transform(d, date=as.Date(paste(0, year, month, day, sep=), %y%m%d))
}

d1 - cleanup(d1)
d2 - cleanup(d2)

d - rbind(d1, d2)
d - transform(d, year=factor(year))

with(d, plot(date,value))

# prettier with ggplot2
library(ggplot2)
qplot(date, value, data=d, colour=year)


HTH,

baptiste


2009/10/7 ogbos okike ogbos.ok...@gmail.com:
 Good morning. I wish to plot two data on the same axis. I tried plot(x,y,
 type = l) for the first and tried to use lines or points(x,y, lty = 2, col
 = 4) to add or plot the second data on alongside the first. However, what I
 got was not encouraging.
 I have attached the two data and would be pleased if anybody could be of
 help.
 Thank you
 Best regards
 Ogbos

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


Re: [R] Slope between two points

2009-10-08 Thread baptiste auguie
Hi,

Like this perhaps?

 slope = diff(y) / diff(x)
 str(slope)
 num [1:499] 1.5068 -1.8406 2.1745 0.0676 -2.6088 ...

HTH,

baptiste

2009/10/8 FMH kagba2...@yahoo.com:
 Dear All,

 Let  499 piece-wise lines were buit up by 500 pair of observations, via R 
 code below.

 x - 1:500
 y - rnorm(500)
 plot(x, y, type = 'b')

 I was trying to compute all the slopes for the  lines which were connected 
 between two adjacent points. For instance, slopes of lines between first and 
 second points, second and third points, and so on, until between  points 499 
 and 500, respectively, but sadly, i never found a suitable function do this 
 computatation efficiently.

 Could someone please advice me on doing this?

 Thank you
 Fir



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


Re: [R] xyplot#strips like ggplot?

2009-10-08 Thread baptiste auguie
Hi,

Try the useOuterStrips function in the latticeExtra package.


HTH,

baptiste

2009/10/8 Christian Ritter crit...@ridaco.be:
 Dear all,

 I want to split the strips in xyplot and push them into the margins ...

 Tried to find this in common documentation (such as Deepayan's book) on
 lattice ... but so far without success ...

 Here is the situation:

 xyplot(Speed~Count|Lane*Day,...)

 where Speed and Count are numeric, Lane and Day are factors.

 By default, this makes a double strip on top of each graph. I can change
 this to make a strip on the left or change the strip layout.

 What I want to do, is to write the strips in the margins of the layout.
 That is, to put the strips corresponding to 'Lane' above the top row of
 graphs and the strips corresponding to 'Day' vertically at the right of
 the graphs. Such as qplot(Count,Speed,facets=Lane~Day) would do in ggplot2.

 Can anyone of you tell me how to do this in an elegant (and fast way).
 [the obvious solution is to take qplot, but it is too SLOW].

 Thanks in advance for your assistance,

 Chris.

 __
 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] proto and get()

2009-10-08 Thread baptiste auguie
Dear all,

In mucking around with ggplot2, I've hit the following snag,

library(ggplot2)

# this returns a grob, OK
GeomAbline$icon()
# lines[GRID.lines.9]

# this returns the function icon, OK
GeomAbline$icon
# proto method (instantiated with ): function (.)
# linesGrob(c(0, 1), c(0.2, 0.8))
# environment: 0x13e6800

Now I want to wrap this in a function,

getIcon - function(geom){
  st - paste(Geom, firstUpper(geom), sep=)

  g - get(st, 2)

  g$icon()
}

getIcon(abline) # still OK
# lines[GRID.lines.10]

but ...

getIcon - function(geom){
  st - paste(Geom, firstUpper(geom), sep=)

  g - get(st, 2)

  g$icon
}
getIcon(abline)
# proto method (instantiated with ):
# Error in get(icon, env = g, inherits = TRUE) : object 'g' not found

So, it seems that I'm being too naive about using get on a proto
object or something along those lines.

I'd be grateful if proto experts could help me extract the icon
function from this object.

Best regards,

baptiste

__
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] proto and get()

2009-10-08 Thread baptiste auguie
... without answering my previous question, I have just found a
fortune-hate workaround,

getIcon - function(geom){
  st - paste(Geom, firstUpper(geom),$icon,  sep=)
  eval(parse(text=st))
}

getIcon(abline)

I'm still curious about the get() behaviour though.

Best,

baptiste

__
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] external variable by inside-function routines modifications

2009-10-08 Thread baptiste auguie
Hi,

with assign,

foo - function(var){
  assign(var, var+1, envir = .GlobalEnv)
}

var =1
foo(2)
var
# [1] 3

HTH,

baptiste



2009/10/8 devol sund...@gmail.com:

 Dear all,

  could you please advice whether it is possible somehow to modify an
 external (from the point of some function view) variable by some
 function-internal operators. For example

 var=1
 foo-function(var){var=var+1}
 foo(var)
 var
 [1] 1

 but the goal is to get the var equal to 2 in this specific case.

 Thanks!
 --
 View this message in context: 
 http://www.nabble.com/external-variable-by-inside-function-routines-modifications-tp25803308p25803308.html
 Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] field names as function parameters

2009-10-11 Thread baptiste auguie
Hi,

I think this is a case where you should use the ?[[ extraction
operator rather than $,

d = data.frame(a=1:3)
mytarget = a
d[[mytarget]]


HTH,

baptiste

2009/10/11 tdm ph...@philbrierley.com:

 Hi,

 I am passing a data frame and field name to a function. I've figured out how
 I can create the formula based on the passed in field name, but I'm
 struggling to create a vector based in that field.

 for example if I hard code with the actual field name

 Y = df$Target, everything works fine.

 but if I use the passed in parameter name, it doesn't give me what I want,

 Y = df$mytarget


 Here is the function,

 # trying to pass field name to a function
 logistictest - function(df,mytarget)
 {

 #library for AUC calculation
 library(caTools)

 #build logistic model
 mytarget - deparse(substitute(mytarget))
 myformula - paste(mytarget, ~ .)
 myformula - deparse(substitute(myformula))
 logistic_reg - glm(myformula , data=df, family=binomial(link=logit))
 print(model build OK)

 #score up
 scores - predict(logistic_reg, type=response, df)
 print(model scored OK)

 #calc AUC
 Y = df$mytarget

 auc - colAUC(scores,Y)
 print(auc calculated OK)

 }

 logistictest(df=trainset,mytarget=Target)


 [1] model build OK
 [1] model scored OK
 Error in as.vector(x, mode) : invalid 'mode' argument

 --
 View this message in context: 
 http://www.nabble.com/field-names-as-function-parameters-tp25838606p25838606.html
 Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Manipulating Arrays

2009-10-11 Thread baptiste auguie
Hi,

the abind package can help you with the first query,

## add values
library(abind)
arr - abind(arr,arr[1,,,] * 2 + 1,along=1)
dim(arr)

as for the second, maybe you can use negative indexing,

## remove values
arr - arr[-2,,,]

HTH,

baptiste

2009/10/11 ampc ampc2...@gmail.com:

 Manipulating Arrays
 Using the below data:

 df - structure(list(dim1 = structure(c(1L, 3L, 1L, 4L, 1L, 2L, 2L,
 2L, 3L, 1L, 4L, 3L, 4L, 4L, 3L, 2L), .Label = c(a1, a2, a3,
 a4), class = factor), dim2 = structure(c(2L, 1L, 2L, 2L,
 4L, 3L, 1L, 3L, 1L, 3L, 2L, 4L, 3L, 4L, 1L, 4L), .Label = c(b1,
 b2, b3, b4), class = factor), dim3 = structure(c(1L,
 4L, 3L, 2L, 1L, 1L, 2L, 4L, 3L, 2L, 2L, 3L, 3L, 1L, 4L, 4L), .Label =
 c(c1,
 c2, c3, c4), class = factor), dim4 = structure(c(2L,
 4L, 1L, 3L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 4L, 1L, 4L, 1L, 4L), .Label =
 c(d1,
 d2, d3, d4), class = factor), value = c(33L, 28L, 97L,
 64L, 95L, 64L, 21L, 76L, 93L, 50L, 30L, 7L, 89L, 57L, 27L, 14L
 )), .Names = c(dim1, dim2, dim3, dim4, value), class =
 data.frame, row.names = c(NA,
 -16L))

 library(reshape)
 arr - cast(df, dim1~dim2~dim3~dim4, sum)

 dim(arr)
 [1] 4 4 4 4

 How do I manipulate this array?


 1. Can I add an extra element in the first dimension using the existing
 dimensions? As in a dataframe? Such as (The below does not work)

 arr[5,,,] - arr[1,,,] * 2 + 1
 Error in arr[5, , , ] - arr[1, , , ] * 2 + 1 : subscript out of bounds

 2. How do I remove say the 2 element of the first dimension and have other
 elements re-arranged in the logical way
 i.e deleting arr[2,,,] means arr[3,,,] becomes arr[2,,,]; and arr[4,,,]
 becomes arr[3,,,]
 (again the below does not work)
 arr[2,,,] - NULL

 Error in arr[2, , , ] - NULL :
  number of items to replace is not a multiple of replacement length


 --
 View this message in context: 
 http://www.nabble.com/Manipulating-Arrays-tp25838608p25838608.html
 Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] add lines() to 1st plot in layout() after calling 2nd plot()?

2009-10-12 Thread baptiste auguie
Interesting, I hadn't tried this but it probably explains why
navigation to different regions of a layout is neither documented nor
advisable.

Yet another alternative is to use Grid graphics. In particular,

1- lattice or ggplot2 provide ways to arrange several plots in a
rectangular layout, with several options to add output to a specific
panel (but they do require quite a different approach to the creation
of plots)

2- for simple enough plots (or for brave users) you could also use
low-level grid commands, and navigate to different viewports
arbitrarily placed on a page.

3- the gridBase package provides a way to combine (with some
limitations) the power of grid layouts and the output produced with
base graphics.

Best,

baptiste



2009/10/12 Greg Snow greg.s...@imail.org:
 This only works if all the plots are the same size and the defaults are used 
 for the margins.  Try it with different sized figure regions in layout, the 
 added lines don't match at the end.

 --
 Gregory (Greg) L. Snow Ph.D.
 Statistical Data Center
 Intermountain Healthcare
 greg.s...@imail.org
 801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of baptiste auguie
 Sent: Sunday, October 04, 2009 3:33 AM
 To: r-help
 Subject: Re: [R] add lines() to 1st plot in layout() after calling 2nd
 plot()?

 Hi,

 Try this,

 dev.new()
 layout(matrix(1:4,2, by=T))

 plot(1:10,main=top left plot)
 plot(1:10,main=top right plot)
 plot(1:10,main=bottom left plot)
 plot(1:10,main=bottom right plot)

 for (ii in 1:2){
 for (jj in 1:2){
 par(mfg=c(ii,jj))
 text(5,2, lab=paste(plot #:,ii,,,jj,sep=))
 }
 }
 par(mfg=c(1,1))
 lines(c(3:7,7:3),col=red)

 HTH,

 baptiste
 2009/10/4 Marianne Promberger marianne.promber...@kcl.ac.uk:
  Thanks for the quick reply. However ...
 
  David Winsemius dwinsem...@comcast.net 03-Oct-09 20:50:
  MP layout(matrix(c(1,2),1))
  MP plot(1:10,main=left plot)
  MP plot(10:1,main=right plot)
  MP lines(c(3:7,7:3),col=red)
  MP
  MP but of course now lines() gets added to the right plot. I
  MP
  MP Is there any way to make the lines() go to the fist plot (left
  MP plot)?
 
  If you look at layout's help page there appears to be a worked
 example
  of an even more complex task. The answer appears to be assingning
  numbers to regions and then inserting par(mar=  with an
 appropriately
  constructed destination arguments prior to each added piece.
 
  Sorry, but I fail to find the solution in the page returned by
  ?layout, assuming that's what you mean.
 
  Yes, the numbers in the matrix given to layout() give the order of
  where plots will be put, so
 
  layout(matrix(c(2,1),1))
 
  then
 
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  puts left plot on the right hand side and right plot on the
  left. But the lines() still go to the right plot plot (now on the
  left hand side) which gets called last.
 
  The par(mar ... of the scatterplot with marginal histograms example
  just set the margins of the histogram plots, then they get plotted to
  the region with the next number given in the layout() matrix.
 
  Maybe I'm missing something.
 
  Thanks,
 
  Marianne
 
 
  --
  David
 
  On Oct 3, 2009, at 3:15 PM, Marianne Promberger wrote:
 
  Dear R users,
 
  I create a graphic with two plots side by side using layout(), like
  this:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  lines(c(3:7,7:3),col=red)
  plot(10:1,main=right plot)
 
  The lines() obivously get added to the left plot plot.
 
  Now, I'm trying to write a function that builds up a plot bit by
 bit
  to
  then include it in a LaTeX presentation with overlays. I'm using
  dev.copy(), and it would make my life much easier (because in fact
 I
  call all sorts of additional axis() etc after plot) if I could call
  the above commands in this order:
 
  layout(matrix(c(1,2),1))
  plot(1:10,main=left plot)
  plot(10:1,main=right plot)
  lines(c(3:7,7:3),col=red)
 
  but of course now lines() gets added to the right plot. I
 
  Is there any way to make the lines() go to the fist plot (left
  plot)?
 
  Marianne
 
 
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
 
  __
  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.
 
  --
  Marianne Promberger PhD, King's College London
  http://promberger.info
  R version 2.9.2 (2009-08-24)
  Ubuntu 9.04
 
  __
  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

Re: [R] Scatter plot using icons (from a gif) instaed of points - is it possible ?

2009-10-14 Thread baptiste auguie
Hi,

You'll probably find that there are two parts to your query:

1- import a bitmap into R, for this I'd suggest the wiki page,
http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-misc:display-images

2- place the image (now some sort of matrix of colour points) at
different locations on a graph. I don't know any function to do this
(*) (but there may be some listed in the above webpage).

Another option is to convert the bitmap to vector graphics using an
external tool, then use the grImport package to create a grob
(graphical object) that you can then place in any Grid-based plot
(there is an example with lattice).


HTH,

baptiste

(*) this may look like a starting point:
http://wiki.r-project.org/rwiki/doku.php?id=tips:graphics-grid:displaybitmap





2009/10/14 Tal Galili tal.gal...@gmail.com:
 Hello dear R-help group.

 I wish to plot a scatter plot using icons (or images) instead of points.
 Is it possible? and how so?

 Thanks,
 Tal






 --


 My contact information:
 Tal Galili
 E-mail: tal.gal...@gmail.com
 Phone number: 972-52-7275845
 FaceBook: Tal Galili
 My Blogs:
 http://www.talgalili.com (Web and general, Hebrew)
 http://www.biostatistics.co.il (Statistics, Hebrew)
 http://www.r-statistics.com/ (Statistics,R, English)

        [[alternative HTML version deleted]]

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


Re: [R] Code improvement

2009-10-22 Thread baptiste auguie
Hi,

I don't know if it helps, but looking at the output of xyplot you can
extract the legend (a grid.frame) as follows,

library(grid)
library(lattice)

p = xyplot(x~y, group=x,data=data.frame(x=1:10,y=1:10),
auto.key=list(space=right))
legend = with(p$legend$right, do.call(lattice:::drawSimpleKey, args))
grid.draw(legend)

and lattice::draw.key might also help if you need to customize the legend.


HTH,

baptiste


2009/10/22 Sebastien Bihorel sebastien.biho...@cognigencorp.com:
 Dear R-Users,

 I would like to have the opinion of the list on the following matter. I have
 this generic function that creates multiple lattice scatterplots per page
 based upon different subsets of the same dataset. The use of different
 line/point colors/symbols  in each plot is based upon a 'group' variable',
 which is the same for all plots. My goal is to create a main legend per
 page:
 1- because the 'group' variable' is the same for all plots, one legend per
 page is sufficient;
 2- because the subset of data used for a particular scatterplot does not
 have to contain all unique elements of the group variable in the whole
 dataset, the graphical settings need to be adjusted for each plot based upon
 a general list of settings created from the whole dataset prior to the
 creation of the plots;
 3- for the same reason, I cannot use the key argument of xyplot to create a
 legend from the first scatterplot.

 Another piece of info is that this generic function could be used to create
 very different categories of graphs, which each require a different legend
 design.

 At the moment, I am creating the legend based upon the general graph
 settings and the category of plot. Prior to the creation of the graphs, I
 store grid objects (text, point, line, or rectangle) into a list, with also
 some information about the number of lines that the legend will use, and the
 category of the plot. After the plots are printed to the device, I open a
  viewport at the bottom of my page and split it according to the type of the
 graph and the number of lines it needs. Finally, I just loop through the
 content of the list and draw the grid objects.

 Overall, this is all fine but a bit 'brute force'. Also the final
 'open-a-viewport-and-draw-inside' step is a big messy code within a generic
 graph function, because one specific piece of code is needed per category of
 plot, and because of additional subtleties (conditional argument, etc... )

 Based upon the behavior of the xyplot function, I understand that it would
 be possible to store the fully formatted legend directly at its creation and
 then just 'print' the stored object within my legend viewport. Could anybody
 advise me on the process to follow to accomplish that or maybe a few
 functions to look at?

 As always, any help would be greatly appreciated.

 Sebastien

 __
 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] regular expressions

2009-10-26 Thread baptiste auguie
Dear list,

I have the following text to parse (originating from readLines as some
lines have unequal size),

st = c(START text1 1 text2 2.3, whatever intermediate text, START
text1 23.4 text2 3.1415)

from which I'd like to extract the lines starting with START, and
group the subsequent fields in a data.frame in this format:

  text1  text2
 12.3
  23.4 3.1415


All the lines containing START have the same number of fields, but
this number may vary from file to file.

I have managed to get this minimal example work, but I am at a loss as
for handling an arbitrary number of couples (text value),

library(gsubfn)

( parsed =
strapply(st, ^START +([[:alnum:]]+) +([0-9.]+) +([[:alnum:]]+)
+([0-9.]+),c, simplify=rbind,combine=c) )

d = data.frame(parsed[ ,c(2,4)])
names(d) - apply(parsed[ ,c(1,3)], 2, unique)
d

## this one has more fields: how do I generalize the regular expression?
st2 = c(START text1 1 text2 2.3 text3 5, whatever intermediate
text, START text1 23.4 text2 3.1415 text3 6)

Best regards,


Baptiste

__
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] regular expressions

2009-10-26 Thread baptiste auguie
Perfect, thanks!

baptiste

2009/10/26 Gabor Grothendieck ggrothendi...@gmail.com:
 Assuming only START fields match pat:

 ## this one has more fields: how do I generalize the regular expression?
 st2 = c(START text1 1 text2 2.3 text3 5, whatever intermediate text,
 + START text1 23.4 text2 3.1415 text3 6)

 pat - [[:alnum:]]+ +([0-9.]+)
 s - strapply(st2, pat, c, simplify = rbind)

 pat2 - ([[:alnum:]]+) +[0-9.]+
 colnames(s) - strapply(st2[1], pat2, c, simplify = rbind)
 s
     text1  text2    text3
 [1,] 1    2.3    5
 [2,] 23.4 3.1415 6

 If there are non-START fields that do match pat then grep out the
 START fields first.

 On Mon, Oct 26, 2009 at 9:30 AM, baptiste auguie
 baptiste.aug...@googlemail.com wrote:
 Dear list,

 I have the following text to parse (originating from readLines as some
 lines have unequal size),

 st = c(START text1 1 text2 2.3, whatever intermediate text, START
 text1 23.4 text2 3.1415)

 from which I'd like to extract the lines starting with START, and
 group the subsequent fields in a data.frame in this format:

  text1  text2
     1    2.3
  23.4 3.1415


 All the lines containing START have the same number of fields, but
 this number may vary from file to file.

 I have managed to get this minimal example work, but I am at a loss as
 for handling an arbitrary number of couples (text value),

 library(gsubfn)

 ( parsed =
 strapply(st, ^START +([[:alnum:]]+) +([0-9.]+) +([[:alnum:]]+)
 +([0-9.]+),c, simplify=rbind,combine=c) )

 d = data.frame(parsed[ ,c(2,4)])
 names(d) - apply(parsed[ ,c(1,3)], 2, unique)
 d

 ## this one has more fields: how do I generalize the regular expression?
 st2 = c(START text1 1 text2 2.3 text3 5, whatever intermediate
 text, START text1 23.4 text2 3.1415 text3 6)

 Best regards,


 Baptiste

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


Re: [R] reset par() within plot layout

2009-10-27 Thread baptiste auguie
Hi,

From ?par,

Value

When parameters are set, their former values are returned in an
invisible named list.

Therefore opar - par(col=red) will not contain col=red.

HTH,

baptiste


2009/10/27 Janke ten Holt j.c.ten.h...@rug.nl:
 This seems to work indeed. But I don't understand why... I would think
 that opar contains the par settings, including the col=red, but I
 guess it doesn't. I will look into par's behaviour some more...
 Thank you!

 Janke
 -Peter Ehlers


__
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] Why I get this error? Error in close.connection(f) : invalid connection

2009-10-27 Thread baptiste auguie
Hi,

From ?read.csv

Alternatively, file can be a readable text-mode connection (which
will be opened for reading if necessary, and if so closed (and hence
destroyed) at the end of the function call)

HTH,

baptiste



2009/10/27 Peng Yu pengyu...@gmail.com:
 I don't understand why I can not close 'f'. This may be very simple,
 but I don't see why. Could somebody let me know?

 $ cat gzfile.csv
 ,V1,V2,V3,V4,V5
 1,1,5,9,13,17
 2,2,6,10,14,18
 3,3,7,11,15,19
 4,4,8,12,16,20
 $ Rscript gzfile.R
 f = file(gzfile.csv)
 A = read.csv(f)
 A
  X V1 V2 V3 V4 V5
 1 1  1  5  9 13 17
 2 2  2  6 10 14 18
 3 3  3  7 11 15 19
 4 4  4  8 12 16 20
 close(f)
 Error in close.connection(f) : invalid connection
 Calls: close - close.connection
 Execution halted

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


Re: [R] read.table but more tables at once

2009-10-28 Thread baptiste auguie
Hi,

Try this,

files - paste(RA94010,1:3,sep=)
# or files - list.files(pattern = RA94010)

list.of.data - lapply(files, read.table, header=F)

# if required, collapse into a single data.frame
do.call(rbind, list.of.data)


HTH,

baptiste

2009/10/28 Sybille Wendel wendel.sybi...@googlemail.com:
 Dear all,

 I have a lot of data files (.txt) that I want to read in all at once, if
 possible.
 the files have names in time system. for example: RA940101, RA940102,
 RA940103, RA940104 an so on.
 (meaning: RA, year:91, month: here january, day of the month.)

 I tried something like

 vektor - c(RA940101,RA940102,RA940103)

 for (x in 1:3)
 { data - read.table(paste(vektor[x],sep=),header=F) }

 But how can I put the vektor on the left side, so that data would be instead
 of data the three first days of the year 1994?

 best wishes and thanks a lot for your answers,

 Sybille

        [[alternative HTML version deleted]]

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


Re: [R] ggplot2: Histogram with negative values on x-axis doesn't work

2009-10-30 Thread baptiste auguie
2009/10/30 hadley wickham h.wick...@gmail.com:
 I read anything that mentions
 ggplot2 no matter where it is.


... one should hope this statement only applies to the Internet
though, does it? Please do share your regexp if it's not the case.

:)

baptiste

__
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] superscript troubles

2009-11-02 Thread baptiste auguie
Hi,

Try this,

x = rnorm(1)
y = rnorm(1)
leg = bquote(r^2*=*.(round(x,digits=3))*, P=*.(round(y, digits=3)))
plot.new()
legend (bty =n,topright,legend=leg)

HTH,

baptiste

2009/11/2 Jacob Kasper jacobkas...@gmail.com:
 I know that this has been revisited over and over, yet I cannot figure out
 how to solve this case of superscript troubles...
 I would like the 2 in r2 to be superscript, yet I am pasting text before and
 after it. I have tried several variations but have not solved this yet, any
 suggestions?

 legend (bty =
 n,topright,paste(r2=,round(summary(lat_x)$r.squared,digits=3),,
 P=,round(coefficients(summary(lat_x))[2,4], digits=3)))
 Thank you
 Jacob

 --
 Jacob Kasper
 http://twitter.com/Protect_Oceans
 66°04' N
 23°07' W
 Coastal  Marine Management Master's Student
 University Centre of the Westfjords

 Sundstræti 14                            37 Devens Rd
 Ísafjörður, 400                           Swampscott, MA 01907
 Iceland                                       USA

        [[alternative HTML version deleted]]


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


Re: [R] how to display a string containing greek chrs and variables

2009-11-03 Thread baptiste auguie
Hi,

try this,

plot.new()
x=0.8
text(0.5, 0.5, bquote(rho == .(x)))


HTH,

baptiste
2009/11/3  j.delashe...@ed.ac.uk:

 I'm trying something that I thought would be pretty simple, but it's proving
 quite frustrating...

 I want to display, for instance, the correlation coefficient rho in a
 graph.

 I can do something like:

 text(x, y, paste(rho =, cor))

 where cor would be my previously calculated correlation coefficient, and x
 and y the coordinates.
 Obviously that displays rho, not the greek letter rho.

 I can do also this:

 text(x, y, paste(\\*r =,cor), vfont = c(sans serif,bold))

 that works, but that doesn't look very pretty.
 What looks good is doing something like:

 text(x, y, expression(rho))

 But I haven't managed to make it do what I need.

 I can get this:
 text(x, y, expression(rho == 0.8))

 that looks good, but how can I substitute the 0.8 for teh name of a
 numeric variable whose value is 0.8?

 I'm going slightly mad... it can't be that hard.

 Thanks for any help!

 Jose


 --
 Dr. Jose I. de las Heras                      Email: j.delashe...@ed.ac.uk
 The Wellcome Trust Centre for Cell Biology    Phone: +44 (0)131 6513374
 Institute for Cell  Molecular Biology        Fax:   +44 (0)131 6507360
 Swann Building, Mayfield Road
 University of Edinburgh
 Edinburgh EH9 3JR
 UK
 *
 NEW EMAIL from July'09: nach.mcn...@gmail.com
 *

 --
 The University of Edinburgh is a charitable body, registered in
 Scotland, with registration number SC005336.

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


Re: [R] R and Python

2009-11-04 Thread baptiste auguie
Hi,

It looks like SAGE might be another option,

http://www.sagemath.org/index.html

though I never tried it.

HTH,

baptiste

__
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] Obtaining midpoints of class intervals produced by cut and table

2009-11-08 Thread baptiste auguie
Hi,

Maybe something like this (inspired by ?cut),

cut2num - function(f){
  labs - levels(f)
  d - data.frame(lower = as.numeric( sub(\\((.+),.*, \\1, labs) ),
  upper = as.numeric( sub([^,]*,([^]]*)\\], \\1, labs) ))
  d$midpoints - rowMeans(d)
  d
}

a - c(1, 2, 3, 4, 5, 2, 3, 4, 5, 6, 7)
cut2num(cut(a, 3))

HTH,

baptiste





2009/11/8 jose romero jlauren...@yahoo.com:
 Hello list:

 I am using cut and table to obtain a frequency table from a numeric 
 sample vector.  The idea is to calculate mean and standard deviation on 
 grouped data.  However, I can't extract the midpoints of the class intervals, 
 which seem to be strings treated as factors.  How do i extract the midpoint?

 Thanks,
 jose loreto


        [[alternative HTML version deleted]]


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


Re: [R] Find the first values in vector

2009-11-09 Thread baptiste auguie
Hi,

One way would be,

vec[ cumsum(!vec)==0 ]

HTH,

baptiste

2009/11/9 Grzes gregori...@gmail.com:

 Hi !
 I have a vector:
 vec= TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE TRUE  TRUE  FALSE
 and I'm looking for a method which let me get only the first values equal
 TRUE from this vector. It means that I want to get a vector:
 vec_out =  TRUE  TRUE  TRUE  TRUE

 or posictions values = TRUE: vec_out = 1,2,3,4
 --
 View this message in context: 
 http://old.nabble.com/Find-the-first-values-in-vector-tp26271555p26271555.html
 Sent from the R help mailing list archive at Nabble.com.

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


  1   2   3   4   5   6   7   8   >