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,
# 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:
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),
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
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
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
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,
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 =
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,
9 matches
Mail list logo