Да, я думаю, что расширение ваших данных было бы хорошим подходом.Вот один из способов сделать это, который я применил к длинному формату подмножества фрейма данных iris
.
like_your_data <- structure(list(points = c(5.1, 4.9, 4.7, 4.6, 7, 6.4, 6.9, 5.5,
6.3, 5.8, 7.1, 6.3), outcome = structure(c(1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L), .Label = c("setosa", "versicolor",
"virginica"), class = "factor"), participant = c(1L, 2L, 3L,
4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -12L), .Names = c("points",
"outcome", "participant"))
Сначала я делаю версию, которая является просто сетозой (эквивалентной вашему scd_gb
).Затем я присоединяюсь к версии, которая исключает сетозу.Это приводит к добавлению значений для других в одном столбце и их типа опроса в другом.Это будет хорошо работать с ggplot, так как мы можем сопоставить тип опроса с цветом.
like_your_data %>%
filter(outcome == "setosa") %>% # Equiv to scd_gb
left_join(like_your_data %>%
filter(outcome != "setosa"), by = "participant") %>%
## Output at this point:
# A tibble: 8 x 5
# points.x outcome.x participant points.y outcome.y
# <dbl> <fct> <int> <dbl> <fct>
# 1 5.1 setosa 1 7 versicolor
# 2 5.1 setosa 1 6.3 virginica
# 3 4.9 setosa 2 6.4 versicolor
ggplot(aes(points.x, points.y, color = outcome.y)) + geom_point()
![enter image description here](https://i.stack.imgur.com/DFBSF.png)