group by two factors

Published onesixx on

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
Categories: R ggplot2

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x