I'm trying to plot some longitudinal data across two phases of a treatment (baseline phase, treatment phase) with two experimental conditions (Condition one and condition two).
When I use color = condition, and group = phase, geom_line() doesn't group by condition (plot 1 below). If I use group = condition, the two conditions are appropriately grouped in the plot, however, I lose the break between the baseline and treatment phases which I would like to keep. How can I acheive a plot that looks like #2 below, but has no line between sessions 5 and 6? Thanks!
Reprex:
library(tidyverse)
tibble(
session = rep(seq(1,10,1),2),
phase = rep(c(rep("baseline", 5), rep("treatment", 5)), 2),
condition = c(rep("one", 10), rep("two", 10)),
score = c(1, 2, 2, 4, 3, 5, 7, 8, 10, 9, 2, 4, 3, 3, 4, 7, 8, 9, 9, 10)
) %>%
ggplot(aes(x = session, y = score, group = phase, color = condition)) +
geom_line() +
geom_point()
library(tidyverse)
tibble(
session = rep(seq(1,10,1),2),
phase = rep(c(rep("baseline", 5), rep("treatment", 5)), 2),
condition = c(rep("one", 10), rep("two", 10)),
score = c(1, 2, 2, 4, 3, 5, 7, 8, 10, 9, 2, 4, 3, 3, 4, 7, 8, 9, 9, 10)
) %>%
ggplot(aes(x = session, y = score, group = condition, color = condition)) +
geom_line() +
geom_point()