group by two factors
dd <- mtcars %>% data.table() col <- c("gear","carb") dd[ , (col):= lapply(.SD, as.factor), .SDcols=col] p <- dd %>% ggplot(aes(x=hp, y=disp, color=carb)) + \t\t geom_point(aes(shape=gear)) p <- p + geom_line(aes(group=interaction(gear,carb))) p