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),
  treatment=factor(sample(letters[1:2], 10, TRUE)))

myplot(x="Xmeas", y="Ymeas", data=d) + # adding custom specifications
  aes_string(size="treatment") +
  ylab("this is my label") +
  theme_bw()

HTH,

baptiste


2009/9/14 Polwart Calum (County Durham and Darlington NHS Foundation Trust)
<calum.polw...@nhs.net>

> >
> > # 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:
>
> myplot( mydfr$Xmeas, mydfr$Ymeas )
>
> So plot doesn't know that treatment is within mydfr...
>
> changing your function to:
>
> myplot <- function(...) {
> plot(...,
>       pch=19,
>       col=c("blue","red")mydfr$[treatment]
>      )
> }
>
> should work?
>
>
> ********************************************************************************************************************
>
> This message may contain confidential information. If ...{{dropped:29}}

______________________________________________
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] How ... Remko Duursma
    • Re:... Polwart Calum (County Durham and Darlington NHS Foundation Trust)
      • ... baptiste auguie
      • ... Remko Duursma
        • ... Paul Hiemstra
          • ... Remko Duursma
            • ... Paul Hiemstra
              • ... David Winsemius
      • ... Polwart Calum (County Durham and Darlington NHS Foundation Trust)

Reply via email to