是否可以按两列分组?所以交叉产品是由geom_point()
和geom_smooth()
?
例如:
frame <- data.frame(series <- rep(c('a', 'b'), 6), sample <- rep(c('glass',
'water', 'metal'), 4), data <- c(1:12))
ggplot(frame, aes()) # ...
Run Code Online (Sandbox Code Playgroud)
这样点6
和12
分享一组,但没有3
.
Blu*_*ter 148
以这个问题为例,使用interaction
将两列组合成一个新因子:
# Data frame with two continuous variables and two factors
set.seed(0)
x <- rep(1:10, 4)
y <- c(rep(1:10, 2)+rnorm(20)/5, rep(6:15, 2) + rnorm(20)/5)
treatment <- gl(2, 20, 40, labels=letters[1:2])
replicate <- gl(2, 10, 40)
d <- data.frame(x=x, y=y, treatment=treatment, replicate=replicate)
ggplot(d, aes(x=x, y=y, colour=treatment, shape = replicate,
group=interaction(treatment, replicate))) +
geom_point() + geom_line()
Run Code Online (Sandbox Code Playgroud)
Dav*_*jad 57
例如:
qplot(round, price, data=firm, group=id, color=id, geom='line') +
geom_smooth(aes(group=interaction(size, type)))
Run Code Online (Sandbox Code Playgroud)
jor*_*ran 30
为什么不paste
将这两个列放在一起并将该变量用作组?
frame$grp <- paste(frame[,1],frame[,2])
Run Code Online (Sandbox Code Playgroud)
一种更正式的方法是使用该功能interaction
.
归档时间: |
|
查看次数: |
65100 次 |
最近记录: |