在ggplot2中由两列组成 [英] group by two columns in ggplot2

查看:105
本文介绍了在ggplot2中由两列组成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以按两列分组?因此,交叉产品被 geom_point() geom_smooth()

b
$ b

例如:

  frame < -  data.frame(series<  -  rep (c('a','b'),6),sample <-rep(c('glass',
'water','metal'),4),data <-c(1 :12))

ggplot(frame,aes())#...

这样, 6 和 12 点共享一个组,但不是 3

解决方案

为什么不只是粘贴这两列合在一起并使用 变量作为组?

  frame $ grp<  -  paste(框架[,1],框架[,2])

可以使用交互


功能

Is it possible to group by two columns? So the cross product is drawn by geom_point() and geom_smooth()?

As example:

frame <- data.frame(series <- rep(c('a', 'b'), 6), sample <- rep(c('glass',
'water', 'metal'), 4), data <- c(1:12))

ggplot(frame, aes()) # ...

Such that the points 6 and 12 share a group, but not with 3.

解决方案

Why not just paste those two columns together and use that variable as groups?

frame$grp <- paste(frame[,1],frame[,2])

A somewhat more formal way to do this would be to use the function interaction.

这篇关于在ggplot2中由两列组成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆