我模拟这个data.frame
:拆分数据帧分成两组
library(plyr); library(ggplot2)
count <- rev(seq(0, 500, 20))
tide <- seq(0, 5, length.out = length(count))
df <- data.frame(count, tide)
count_sim <- unlist(llply(count, function(x) rnorm(20, x, 50)))
count_sim_df <- data.frame(tide=rep(tide,each=20), count_sim)
它可以绘制这样的:
ggplot(df, aes(tide, count)) + geom_jitter(data = count_sim_df, aes(tide, count_sim), position = position_jitter(width = 0.09)) + geom_line(color = "red")
我现在想count_sim_df
分成两组:high
和low
。当我绘制分割count_sim_df
时,它应该看起来像这样(绿色和蓝色的所有内容都是photoshopped)。我发现棘手的位在high
和low
之间的重叠在tide
的中间值附近。
这是我想count_sim_df
分为高,低:
- 分配的
count_sim_df
一半high
和count_sim_df
一半low
- 重新分配的
count
值来high
和low
之间创建重叠大约在中间值tide
问题编辑做出更加明确了如何创建重叠 – luciano