[R] Alternative to xyplot()?

hadley wickham h.wickham at gmail.com
Wed Jul 18 06:28:52 CEST 2007

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.

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


More information about the R-help mailing list