Hello list, Is anyone aware of a non-lattice-based alternative to xyplot()? Thanks! Manuel
Alternative to xyplot()?
6 messages · Gavin Simpson, Manuel Morales, Ben Bolker +2 more
On Tue, 2007-07-17 at 16:39 -0400, Manuel Morales wrote:
Hello list, Is anyone aware of a non-lattice-based alternative to xyplot()?
x <- rnorm(20) y <- rnorm(20) plot(x, y) ? If you mean some specific aspect of xyplot(), you'll have to tell us what this is. HTH G
On Tue, 2007-07-17 at 22:18 +0100, Gavin Simpson wrote:
On Tue, 2007-07-17 at 16:39 -0400, Manuel Morales wrote:
Hello list, Is anyone aware of a non-lattice-based alternative to xyplot()?
x <- rnorm(20) y <- rnorm(20) plot(x, y) ? If you mean some specific aspect of xyplot(), you'll have to tell us what this is. HTH G
Sorry. I was thinking of the "groups" functionality, as illustrated
below:
grps<-rep(c(1:3),10)
x<-rep(c(1:10),3)
y<-x+grps+rnorm(30)
library(lattice)
xyplot(y~x,group=grps, type=c("r","p"))
Manuel Morales <Manuel.A.Morales <at> williams.edu> writes:
Sorry. I was thinking of the "groups" functionality, as illustrated
below:
grps<-rep(c(1:3),10)
x<-rep(c(1:10),3)
y<-x+grps+rnorm(30)
library(lattice)
xyplot(y~x,group=grps, type=c("r","p"))
The points (type "p") are easy, the regression lines (type "r") are a little
harder. How about:
plot(y~x,col=grps)
invisible(mapply(function(z,col) {abline(lm(y~x,data=z),col=col)},
split(data.frame(x,y),grps),1:3))
cheers
Ben Bolker
What's wrong with lattice? Here's an alternative:
library(ggplot2)
ggplot(data=data.frame(x,y,grps=factor(grps)),
mapping=aes(x=x,y=y,colour=grps)) + # define data
geom_identity() + # points
geom_smooth(method="lm") # regression line
--- Ben Bolker <bolker at ufl.edu> wrote:
Manuel Morales <Manuel.A.Morales <at> williams.edu> writes:
Sorry. I was thinking of the "groups" functionality, as illustrated
below:
grps<-rep(c(1:3),10)
x<-rep(c(1:10),3)
y<-x+grps+rnorm(30)
library(lattice)
xyplot(y~x,group=grps, type=c("r","p"))
The points (type "p") are easy, the regression lines (type "r") are a
little
harder. How about:
plot(y~x,col=grps)
invisible(mapply(function(z,col) {abline(lm(y~x,data=z),col=col)},
split(data.frame(x,y),grps),1:3))
cheers
Ben Bolker
______________________________________________ R-help at stat.math.ethz.ch 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.
On 7/18/07, Stephen Tucker <brown_emu at yahoo.com> wrote:
What's wrong with lattice? Here's an alternative:
library(ggplot2)
ggplot(data=data.frame(x,y,grps=factor(grps)),
mapping=aes(x=x,y=y,colour=grps)) + # define data
geom_identity() + # points
geom_smooth(method="lm") # regression line
I think you mean geom_point() not geom_identity()! Also, if you just want groups, and not colours you can use the group aesthetic. library(ggplot2) qplot(x, y, group=grps) + geom_smooth(method=lm) # You can have different grouping in different layers qplot(x, y, colour=factor(grps)) + geom_smooth(method=lm) qplot(x, y, colour=factor(grps)) + geom_smooth(aes(group=1), method=lm) You can see more examples of ggplot2 in use at http://had.co.nz/ggplot2 Hadley