gpt4 book ai didi

r - ggplot2中的两列分组

转载 作者:行者123 更新时间:2023-12-02 11:24:34 25 4
gpt4 key购买 nike

是否可以按两列分组?于是叉积就画出来了通过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()) # ...

这样点612共享一个组,但不与3共享。

最佳答案

this question 为例,使用交互将两列组合成一个新因子:

# 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()

ggplot example

关于r - ggplot2中的两列分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9968976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com