[R] How to set default plotting colors by treatment?

2009-09-14 Thread Remko Duursma
Dear R-helpers, I have a number of dataframes that looks something like this: mydfr - data.frame(treatment=c(rep(A,3),rep(B,3)), Xmeas=1:6, Ymeas=c(2,4,3,3,5,6)) # except with many more variables, which I plot all the time colored by treatment to quickly check things: with(mydfr, plot(Xmeas,

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Polwart Calum (County Durham and Darlington NHS Foundation Trust)
# I tried defining a function like this myplot - function(...)plot(..., pch=19, col=c(blue,red)[treatment]) # So i can call it like this: with(mydfr, myplot(Xmeas, Ymeas)) # but: Error in plot.xy(xy, type, ...) : object 'treatment' not found basically that is something like calling:

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread baptiste auguie
Hi, Using ggplot2, you could do something like this, library(ggplot2) myplot - function(x, y, data, geom=point){ ggplot(data=data, map=aes_string(x=x, y=y, colour = treatment) ) + layer(geom=geom) + scale_colour_manual(values=c(red, blue)) } d = data.frame(Xmeas=rnorm(10), Ymeas=rnorm(10),

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Remko Duursma
col=c(blue,red)mydfr$[treatment] Yes, but I would like to use the function for lots of other dataframes as well, so embedding 'mydfr' in the function is not the ideal solution... remko - Remko Duursma Post-Doctoral Fellow Centre for Plants and

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Paul Hiemstra
Remko Duursma wrote: col=c(blue,red)mydfr$[treatment] Yes, but I would like to use the function for lots of other dataframes as well, so embedding 'mydfr' in the function is not the ideal solution... The problem is that the info in 'treatment' is non-constant, and you need to either

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Remko Duursma
The example is reproducible! Did you see the first post? remko - Remko Duursma Post-Doctoral Fellow Centre for Plants and the Environment University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Polwart Calum (County Durham and Darlington NHS Foundation Trust)
col=c(blue,red)mydfr$[treatment] Yes, but I would like to use the function for lots of other dataframes as well, so embedding 'mydfr' in the function is not the ideal solution... In that case I'd try something like: myplot - function(..., tmnt) { plot(..., pch=19,

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread Paul Hiemstra
I offer my sincere apologies for not reading the e-mail carefully, your example is indeed reproducible. When you stop using the 'with' function, this is I think what you would like: myplot2 = function(formula, data, ...) { plot(formula, data = data, ..., pch = 19, col =

Re: [R] How to set default plotting colors by treatment?

2009-09-14 Thread David Winsemius
On Sep 14, 2009, at 8:00 AM, Paul Hiemstra wrote: I offer my sincere apologies for not reading the e-mail carefully, your example is indeed reproducible. When you stop using the 'with' function, this is I think what you would like: myplot2 = function(formula, data, ...) { plot(formula,