group by two columns in ggplot2

Published onesixx on

https://stackoverflow.com/questions/9968976/group-by-two-columns-in-ggplot2
# Data frame with two continuous variables and two factors 
set.seed(666)
dd <- data.frame(x=rep(1:10, 4),
                 y=c(rep(1:10, 2)+rnorm(20)/5, rep(6:15, 2) + rnorm(20)/5),
                 treatment=gl(2, 20, 40, labels=letters[1:2]),
                 replicate=gl(2, 10, 40))

dd %>% ggplot(aes(x=x, y=y, colour=treatment, 
                  shape = replicate,
                  group=interaction(treatment, replicate))) + 
        geom_point() + geom_line()
      


dd1 <- data.frame(x=rep(1:40),
                 y=c(rep(1:10, 2)+rnorm(20)/5, rep(6:15, 2) + rnorm(20)/5),
                 treatment=gl(2, 20, 40, labels=letters[1:2]),
                 replicate=gl(2, 10, 40))

dd1 %>% ggplot(aes(x=x, y=y, colour=treatment, 
                         shape = replicate,
                         group=interaction(treatment, replicate))) + 
        geom_point() + geom_line()
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