可以在组内的组中调用geom_smooth吗?

时间:2019-01-15 17:11:50

标签: r ggplot2

我正在实验室实验中探索一些关系,并且在弄清楚如何使线性dta %>% mutate_if(.predicate = f_rlang_check, .funs = funs(. + 10)) 元素适合组中的组时遇到麻烦。

Here are some data,这些数据的标题(在示例中称为geom_smooth)和我现在所在的位置图(已链接,因为我尚未获得插入图像的权限) :

reprex.code

Plot x by y, with grouped geom_smooth function

这当前为我的每个组(共5个)呈现线性# A tibble: 6 x 5 id x y group treatment <fct> <int> <dbl> <chr> <chr> 1 3.3 1 3.5 b1 zone.3 2 3.3 2 1.95 b1 zone.3 3 3.3 3 1.53 b1 zone.3 4 3.3 4 1.68 p1 zone.3 5 3.3 5 5.27 p1 zone.3 6 3.3 6 4.20 p1 zone.3 reprex.code %>% ggplot() + geom_point(mapping = aes(x = x, y = y, color = id)) + geom_smooth(mapping = aes(x = x, y = y, col = group), method = "lm", se = FALSE) + scale_x_continuous(breaks = unique(reprex.code$x)) + theme_minimal() 。我想做的是在该组中添加另一个组;导致组变量中的6个id因子中的每个geom_smooth(在上面链接的图中显示为颜色)。这将导致5组中的每组总共有6 lm的装配-总共30 lms。

1 个答案:

答案 0 :(得分:0)

对于每个mikeck,解决方案是指定color = interaction(group, id) in the geom_smooth`调用。