Semior001

Untitled

Jul 22nd, 2018
434
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. library(ggplot2)
  2.  
  3. df <- read.csv("psyexperiment.csv")
  4.  
  5. # first task
  6. ggplot(df, aes(x=agree, fill=gender)) +
  7.   geom_bar(position="dodge") +
  8.   xlab("Did the student agree?") +
  9.   ylab("Number of cases") +
  10.   ggtitle("Correlation between agreeing and gender")
  11.  
  12. # second task
  13. p <- ggplot(df, aes(y=gender, x=agree)) +
  14.   geom_count(color="#add8e6", show.legend = F) +
  15.   ggtitle("Yet another correlation between agreeing and gender") +
  16.   ylab("Students gender") +
  17.   xlab("Did the student agree?") +
  18.   scale_size_continuous(range = c(11, 20))
  19. p + geom_text(data = ggplot_build(p)$data[[1]],
  20.               aes(x,y,label=n))
  21.  
  22. # third task
  23. female_df <- subset(df, gender == "F" & wave=="third")
  24. ggplot(female_df, aes(x=agree, fill=track)) +
  25.   geom_bar(position="dodge") +
  26.   xlab("Did the student agree?") +
  27.   ylab("Number of cases") +
  28.   ggtitle("Correlation between agreeing and gender", subtitle="Third wave, women")
  29.  
  30. # forth task
  31. library(reshape2)
  32. df <- read.csv("basketball.csv")
  33. df.m <- melt(df)
  34. df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
  35. ggplot(data = df.m, aes(x=variable, y=value)) +
  36.   geom_boxplot() +
  37.   ggtitle("Results by tests") +
  38.   xlab("Test numbers") +
  39.   ylab("Results")
  40.  
  41. # fifth task
  42. library(reshape2)
  43. df <- read.csv("basketball.csv")
  44. df.m <- melt(df)
  45. df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
  46. ggplot(data = df.m, aes(x=variable, y=value)) +
  47.   geom_violin(col="navy", fill="#add8e6", trim=F) +
  48.   ggtitle("Results by tests", subtitle="Lines represent quantiles") +
  49.   xlab("Test numbers") +
  50.   ylab("Results")
  51.  
  52. # sixth task
  53. library(reshape2)
  54. df <- read.csv("basketball.csv")
  55. df.m <- melt(df)
  56. df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
  57. ggplot(df.m, aes(x=ID, y=value, group=variable, col=variable)) +
  58.   geom_point() +
  59.   geom_line() +
  60.   ggtitle("Results by tests for all subjects") +
  61.   ylab("Results") +
  62.   xlab("Subjects") +
  63.   scale_color_discrete("Tests")
  64.  
  65. # seventh task
  66. library(reshape2)
  67. df <- read.csv("basketball.csv")
  68. df$Means <- df$mean
  69. for(i in 1:15){
  70.   df$Medians[i] <- median(c(df$test.1[i],df$test.2[i],df$test.3[i],df$test.4[i],df$test.5[i]))
  71. }
  72. df.m <- melt(df)
  73. df.m <- subset(df.m, variable=="Means" | variable=="Medians")
  74. ggplot(df.m, aes(x=ID, y=value, group=variable, col=variable)) +
  75.   geom_point() +
  76.   geom_line() +
  77.   ggtitle("Means vs. medians for all subjects") +
  78.   ylab("Means and meds") +
  79.   xlab("Subjects") +
  80.   scale_color_discrete("Measures")
RAW Paste Data