交互图 - 重叠顺序
Interaction plot - overlapping order
说,我有这样一个数据框
"hours" "environment" "humidity"
"1" 360 "cold" "dry"
"2" 360 "cold" "dry"
"3" 372 "intermediate" "dry"
"4" 420 "intermediate" "wet"
"5" 456 "warm" "wet"
"6" 432 "warm" "wet"
如您所见,我有一个文件 (bread.txt),每个 environment(冷、中、暖)值都有 2 个样本。我想创建一个交互图,其中我有 2 个样本,并且对于每个样本,它针对 环境 绘制 小时 。到目前为止我最接近的是
r=rep(1:6)
interaction.plot(r,bread$environment,bread$hours)
这是 ggplot()
的一种解决方案:
library(ggplot2)
test <- data.frame(hours=c(360, 360, 372,
420, 456, 432),
environment=c("cold", "cold", "intermediate",
"intermediate", "warm", "warm"),
humidity=c("dry", "dry", "dry",
"wet", "wet", "wet"))
# Add a factor allowing to distinguish between the first and the second sample
test$rep <- rep(1:2)
# plot
ggplot(data=test) +
geom_line(aes(x=rep, y=hours, color=environment))
结果如下:
说,我有这样一个数据框
"hours" "environment" "humidity"
"1" 360 "cold" "dry"
"2" 360 "cold" "dry"
"3" 372 "intermediate" "dry"
"4" 420 "intermediate" "wet"
"5" 456 "warm" "wet"
"6" 432 "warm" "wet"
如您所见,我有一个文件 (bread.txt),每个 environment(冷、中、暖)值都有 2 个样本。我想创建一个交互图,其中我有 2 个样本,并且对于每个样本,它针对 环境 绘制 小时 。到目前为止我最接近的是
r=rep(1:6)
interaction.plot(r,bread$environment,bread$hours)
这是 ggplot()
的一种解决方案:
library(ggplot2)
test <- data.frame(hours=c(360, 360, 372,
420, 456, 432),
environment=c("cold", "cold", "intermediate",
"intermediate", "warm", "warm"),
humidity=c("dry", "dry", "dry",
"wet", "wet", "wet"))
# Add a factor allowing to distinguish between the first and the second sample
test$rep <- rep(1:2)
# plot
ggplot(data=test) +
geom_line(aes(x=rep, y=hours, color=environment))
结果如下: