Skip to content
Prev 44915 / 398528 Next

Help with multicolored points in one plot

On Thursday 26 February 2004 10:13, David Thibault wrote:
Trellis graphics (using the lattice package in R) has a fairly systematic 
approach for doing this. See example(xyplot) for some examples. For your 
data, a possible usage could be:

x <- c(Group1_Xdata, Group2_Xdata)
y <- c(Group1_Ydata, Group2_Ydata)
g <- c(rep(1, length(Group1_Xdata)), rep(2, length(Group2_Xdata)))

xyplot(y ~ x, groups = g)

or if you want to control the colors

xyplot(y ~ x, groups = g, col = c("red", "blue"))


With base graphics, something similar could be achieved with 

plot(x, y, col = c("red", "blue")[g])

lattice is more systematic in the sense that it has globally modifiable 
settings to control various graphical parameters (not only color) used to 
distinguish between groups, with reasonable defaults.

Hth,

Deepayan