plotting 3 variables on a single plot in ggplot2

前端 未结 2 1692
青春惊慌失措
青春惊慌失措 2021-01-24 17:58

Hi have an experiment which consists of three variables, and I would like to plot them all on a single plot.

This is my df:

AB <- data.frame(block=c(\         


        
2条回答
  •  有刺的猬
    2021-01-24 18:19

    Is this what you mean?

    p_all <- ggplot(AB, aes(x=prime,y=RT,group=interaction(familiarity,block))) +
      geom_line(aes(linetype=familiarity,color=block)) 
    

    Data used:

    AB <- structure(list(block = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 
    2L), .Label = c("A", "B"), class = "factor"), familiarity = structure(c(1L, 
    1L, 2L, 2L, 1L, 1L, 2L, 2L), class = "factor", .Label = c("fam", 
    "unfam")), prime = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L
    ), class = "factor", .Label = c("P", "UP")), RT = c(570.6929, 
    628.7446, 644.6268, 607.4312, 556.3581, 645.4821, 623.5624, 604.4113
    )), .Names = c("block", "familiarity", "prime", "RT"), row.names = c(NA, 
    -8L), class = "data.frame")
    

提交回复
热议问题