I want to plot y
against t
, having several conditions (grouping
s) and several replicate
s. I'd like to color code the grouping
, and have the replicates within a grouping be the same color.
Easy, if I just map the replicate
to e.g. linetype
:
library(ggplot2)
data.frame(t = rep(1:10, 4),
y = 1:40,
grouping = rep(1:2, each = 20) |> as.factor(),
replicate = rep(c(1,2,1,2), each = 10) |> as.factor()) |>
ggplot() +
geom_line(aes(x = t, y = y, color = grouping, linetype = replicate))
But if I don't want different linetypes, I thought I could just use group
, but it doesn't appear to work as I expect. What am I missing?
data.frame(t = rep(1:10, 4),
y = 1:40,
grouping = rep(1:2, each = 20) |> as.factor(),
replicate = rep(c(1,2,1,2), each = 10) |> as.factor()) |>
ggplot() +
geom_line(aes(x = t, y = y, color = grouping, group = replicate))
Created on 2024-10-01 with reprex v2.1.0