Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ggplot2)
- df <- read.csv("psyexperiment.csv")
- # first task
- ggplot(df, aes(x=agree, fill=gender)) +
- geom_bar(position="dodge") +
- xlab("Did the student agree?") +
- ylab("Number of cases") +
- ggtitle("Correlation between agreeing and gender")
- # second task
- p <- ggplot(df, aes(y=gender, x=agree)) +
- geom_count(color="#add8e6", show.legend = F) +
- ggtitle("Yet another correlation between agreeing and gender") +
- ylab("Students gender") +
- xlab("Did the student agree?") +
- scale_size_continuous(range = c(11, 20))
- p + geom_text(data = ggplot_build(p)$data[[1]],
- aes(x,y,label=n))
- # third task
- female_df <- subset(df, gender == "F" & wave=="third")
- ggplot(female_df, aes(x=agree, fill=track)) +
- geom_bar(position="dodge") +
- xlab("Did the student agree?") +
- ylab("Number of cases") +
- ggtitle("Correlation between agreeing and gender", subtitle="Third wave, women")
- # forth task
- library(reshape2)
- df <- read.csv("basketball.csv")
- df.m <- melt(df)
- df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
- ggplot(data = df.m, aes(x=variable, y=value)) +
- geom_boxplot() +
- ggtitle("Results by tests") +
- xlab("Test numbers") +
- ylab("Results")
- # fifth task
- library(reshape2)
- df <- read.csv("basketball.csv")
- df.m <- melt(df)
- df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
- ggplot(data = df.m, aes(x=variable, y=value)) +
- geom_violin(col="navy", fill="#add8e6", trim=F) +
- ggtitle("Results by tests", subtitle="Lines represent quantiles") +
- xlab("Test numbers") +
- ylab("Results")
- # sixth task
- library(reshape2)
- df <- read.csv("basketball.csv")
- df.m <- melt(df)
- df.m <- subset(df.m, variable!="age" & variable !="body.height" & variable != "mean")
- ggplot(df.m, aes(x=ID, y=value, group=variable, col=variable)) +
- geom_point() +
- geom_line() +
- ggtitle("Results by tests for all subjects") +
- ylab("Results") +
- xlab("Subjects") +
- scale_color_discrete("Tests")
- # seventh task
- library(reshape2)
- df <- read.csv("basketball.csv")
- df$Means <- df$mean
- for(i in 1:15){
- 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]))
- }
- df.m <- melt(df)
- df.m <- subset(df.m, variable=="Means" | variable=="Medians")
- ggplot(df.m, aes(x=ID, y=value, group=variable, col=variable)) +
- geom_point() +
- geom_line() +
- ggtitle("Means vs. medians for all subjects") +
- ylab("Means and meds") +
- xlab("Subjects") +
- scale_color_discrete("Measures")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement