使用 Sven 的回答中的数据,您还可以查看 lattice 包,它应该已经与您的 R 安装一起安装:
library(lattice)
# Each group in a separate mini plot
xyplot(y ~ x | group, data = dat)
# All groups in one plot, different colors for each group
# Not at all interesting with the example data you've provided
xyplot(y ~ x, groups=dat$group, data = dat)
以下是每个示例,其中包含更多数据:
set.seed(1)
mydf <- data.frame(
group = sample(letters[1:4], 50, replace = TRUE),
x = runif(50, 0, 7),
y = runif(50, 0, 7)
)
xyplot(y ~ x, groups=mydf$group, data = mydf,
auto.key = list(corner = c(0, .98)), cex = 1.5)
xyplot(y ~ x | group, data = mydf,
auto.key = list(corner = c(0, .98)), cex = 1.5)