Hello, I am trying to make a xyplot plot with points that are different symbols. I want to call the symbol type (pch) from a column in my dataframe. Here is a simplified example. In my real example I also have groups, which I have not included here. This example doesn't change the symbols or colors. Any help you can provide would be appreciated. Thanks, John x<-c(1:12) y<-c(rpois(12,4)) grp<-c(rep(c(3,4), each=6)) z<-c(rep(c(1,2), each=6)) p<-rep(1:3,4) xyplot(y~x|z, cex=1.2, panel=function(x,y,...){ panel.xyplot(x,y,...) pch=p fill=list("black","blue")}) [[alternative HTML version deleted]]
Hi: It's not a perfect solution, but an 'easy' way out is to recognize that some symbols are open and some are filled. If you want fill, use a filled symbol and then change the color. p <- rep(16:18, 4) x<-c(1:12) y<-c(rpois(12,4)) grp<-c(rep(c(3,4), each=6)) z<-c(rep(c(1,2), each=6)) dd <- data.frame(x, y, grp, z, p) xyplot(y ~ x, data = dd, cex = 1.2, pch = dd$p, col = c('black', 'blue')[dd$z]) HTH, Dennis On Thu, Feb 10, 2011 at 1:21 PM, John Poulsen <jpoulsen@whrc.org> wrote:> Hello, > > I am trying to make a xyplot plot with points that are different symbols. I > want to call the symbol type (pch) from a column in my dataframe. Here is a > simplified example. In my real example I also have groups, which I have not > included here. This example doesn't change the symbols or colors. > > Any help you can provide would be appreciated. > > Thanks, > John > > x<-c(1:12) > y<-c(rpois(12,4)) > grp<-c(rep(c(3,4), each=6)) > z<-c(rep(c(1,2), each=6)) > p<-rep(1:3,4) > > xyplot(y~x|z, cex=1.2, > panel=function(x,y,...){ > panel.xyplot(x,y,...) > pch=p > fill=list("black","blue")}) > [[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. >[[alternative HTML version deleted]]
The more common way to do this is to use groups, the default is to have a different color for each group, but you can change that using trellis.par.set: tmp <- trellis.par.get() tmp$superpose.symbol$pch = 0:10 trellis.par.set(tmp) xyplot(Sepal.Width ~ Petal.Width, data=iris, groups=Species, auto.key=TRUE) If you need more control of the symbols than that, then look at the panel.my.symbols function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of John Poulsen > Sent: Thursday, February 10, 2011 2:22 PM > To: r-help at r-project.org > Subject: [R] Calling symbols from dataframe for xyplot > > Hello, > > I am trying to make a xyplot plot with points that are different > symbols. I want to call the symbol type (pch) from a column in my > dataframe. Here is a simplified example. In my real example I also > have groups, which I have not included here. This example doesn't > change the symbols or colors. > > Any help you can provide would be appreciated. > > Thanks, > John > > x<-c(1:12) > y<-c(rpois(12,4)) > grp<-c(rep(c(3,4), each=6)) > z<-c(rep(c(1,2), each=6)) > p<-rep(1:3,4) > > xyplot(y~x|z, cex=1.2, > panel=function(x,y,...){ > panel.xyplot(x,y,...) > pch=p > fill=list("black","blue")}) > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.