plotting 3 variables on a single plot in ggplot2

前端 未结 2 1691
青春惊慌失措
青春惊慌失措 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")
    
    0 讨论(0)
  • 2021-01-24 18:43

    IF you have different datasets for those variables, then you can specify the data

    ggplot()+
      geom_line(data=A, aes(x=prime, y=RT, group=familiarity,linetype=familiarity), size=1) +
      geom_line(data=B, aes(x=prime, y=RT, group=familiarity,linetype=familiarity), size=1)+
      expand_limits(y=c(500,650))
    
    0 讨论(0)
提交回复
热议问题