You can define these classes in your dataframe and put them to use with scale_color_identity and scale_shape_identity.
library(tidyverse)
colors <- palette(rainbow(8))
shapes <- c(16, 15, 17, 18)
times <- c(1,2,3)
combos <- expand.grid(colors, shapes)
index <- rep(seq_len(nrow(combos)), each = 3) #creates a repeated index
combos <- combos[index, ] #store expanded df
example <-
combos %>%
mutate( x = rep(times, times = nrow(.)/length(times))
, y = runif(nrow(.))
)
ggplot(example, aes(x = x, y=y, color = Var1, shape = Var2, group = interaction(Var1, Var2))) +
geom_point() +
geom_line() +
scale_color_identity() +
scale_shape_identity()