Line Graphs for several independent variables


  1. Line graph of a single independent variable. (4.9.2.1 pages 155-158)
    See the textbook for the R code and commands...
    
    It was necessary to use the stack() command to convert a wide format 
      data frame to a long format data frame, or rather to create a long
      format data frame from a wide format data frame.
      
    See section 3.9.4 Reshaping data (covers stack() and melt() functions)
      
    See how melt() is used below to create dataframe t2 
                                      from dataframe textdata2.
    

  2. (Section 4.9.2.2 pages 159-161) Line Graphs for several independent variables
    > textData2 <- read.delim("C:/R/AndyField/TextMessages.dat", header = T)
    
    > names(textData2)
    [1] "Group"      "Baseline"   "Six_months"
    
    > t2 <- melt(textData2, id = c("Group"), measured = c("Baseline", "Six_months"))
    
    > names(t2)
    [1] "Group"    "variable" "value"   
    
    > names(t2)<-c("Group", "Time", "Grammar_Score")
    > names(t2)
    [1] "Group"         "Time"          "Grammar_Score"
    
  3. Creating the ggplot named line. Will show up as gg[9] in Workspace for RStudio Workspace panel.
    > line <- ggplot(t2, aes(Time, Grammar_Score, colour = Group))
       
    > line + stat_summary(fun.y = mean, geom="point") 
           + stat_summary(fun.y = mean, geom = "line", aes(group = Group))
    
    
  4. See Figure 4.30 on page 151 of DSUR textbook.
    > line + stat_summary(fun.y = mean, geom="point") 
           + stat_summary(fun.y = mean, geom = "line", aes(group = Group)) 
           + stat_summary(fun.data = mean_cl_boot, geom = "errorbar", width = 0.2) 
           + labs(x = "Time", y = "Mean Grammar Score", colour = "Group")