library(prepdat) 
## Warning: package 'prepdat' was built under R version 3.6.2
library(dplyr) 
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(reshape2)
library(ggplot2)
library(RColorBrewer)

data<-read.table("dataset.txt",header = TRUE)
mydata<-filter(data,rt<1450)

Q2 - 100 bins - axes - 4 histograms - colors - themes - bin sizes - 1 non default color theme - show outlines -

ggplot(data=mydata,aes(x=rt,fill=correctresponse))+geom_histogram(stat = "bin",binwidth=20, bins = 100,show.legend=TRUE,inherit.aes=TRUE)+labs(y="Count",x="Response Time",title="Histogram of Response Time",subtitle = "Histogram with Default Colors, 100 bins and without outlines",fill="Correct Response")

ggplot(data=mydata,aes(x=rt,fill=correctresponse))+geom_histogram(stat = "bin",binwidth=20, bins = 100,show.legend=TRUE,inherit.aes=TRUE)+ scale_fill_manual(values = c("#07FF30","#00EFFF"))+labs(y="Count",x="Response Time",title="Histogram of Response Time",subtitle = "Histogram with Non-Default Colors, 100 bins and without outlines",fill="Correct Response")

ggplot(data=mydata,aes(x=rt,fill=cut(rt,10)))+geom_histogram(color="black",stat="bin",binwidth = 50,bins=100,show.legend=FALSE,inherit.aes=TRUE)+labs(y="Count",x="Response Time",title="Histogram of Response Time",subtitle = "Histogram with Default Color Fill, 100 bins and with outlines")+theme_minimal()

ggplot(data=mydata,aes(x=rt))+geom_histogram(stat="bin",binwidth =25,color="black",fill="blue",bins=100,show.legend=FALSE,inherit.aes=TRUE)+labs(y="Count",x="Response Time",title="Histogram of Response Time",subtitle = "Histogram with Non-Default Color Fill, 100 bins and without outlines")+theme_light()

ggplot(data=mydata,aes(x=rt,color=cut(rt,10),fill=cut(rt,10)))+geom_histogram(color="black",stat="bin",binwidth = 25,bins=100,show.legend=FALSE,inherit.aes=TRUE)+labs(y="Count",x="Response Time",title="Histogram of Response Time",subtitle = "Histogram with 100 bins, Non-Default Color Fill,classic theme and with outlines")+scale_fill_discrete(h = c(250, 350))+theme_classic()

ggplot(data=mydata,aes(x=rt))+geom_histogram(binwidth=25,color="black",fill="orange",aes(y=..density..))+labs(y="Count",x="Response Time",title="Histogram of Response Time")+geom_density()

##response time

ggplot(data=mydata,aes(x=rt))+geom_histogram(binwidth=25,fill="orange")+labs(y="Count",x="Response Time",title="Histogram of Response Time")+facet_wrap(.~subnum,scales="free_y")

ggplot(data=mydata,aes(x=rt))+geom_histogram(binwidth=25,fill="orange")+labs(y="Count",x="Response Time",title="Histogram of Response Time")+facet_wrap(.~subnum)

mynewdata<-filter(mydata,subnum==c(101,102,104,105,108,109,110,111,112,113,136,138,139,162,164,165,166,167))
## Warning in subnum == c(101, 102, 104, 105, 108, 109, 110, 111, 112, 113, :
## longer object length is not a multiple of shorter object length
ggplot(data=mynewdata,aes(x=rt))+geom_histogram(binwidth=25,fill="orange")+labs(y="Count",x="Response Time",title="Histogram of Response Time")+facet_wrap(.~subnum)

###### trials

ggplot(data=mydata,aes(x=trial))+geom_histogram(binwidth=25,color="black",fill="green")+labs(y="Count",x="Trials",title="Histogram of Trials")+facet_wrap(.~subnum,scales="free_y")

ggplot(data=mydata,aes(x=trial))+geom_histogram(binwidth=25,color="black",fill="green")+labs(y="Count",x="Trials",title="Histogram of Trials")+facet_wrap(.~subnum)

# 106,133,161
mytrialdata<-filter(mydata,subnum==c(101,102,103,104,105,108,109,110,111,112,113,132,135,136,138,139,162,163,164,165,166,167))

ggplot(data=mytrialdata,aes(x=trial))+geom_histogram(binwidth=25,color="black",fill="green")+labs(y="Count",x="Trials",title="Histogram of Trials")+facet_wrap(.~subnum)

ggplot(data=mydata,aes(x=rt,y=trial,color=stim))+geom_point()+labs(y="Trials",x="Response Time",title="Response Time and Trials")+geom_smooth()+theme_bw()
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'

ggplot(data=mydata,aes(x=rt,y=trial,color=stim))+geom_point()+labs(y="Trials",x="Response Time",title="Response Time and Trials")+geom_smooth()+theme_bw()+facet_wrap(.~subnum,ncol =2)+geom_line()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : span too small. fewer data values than degrees of freedom.
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : at -3.115
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : radius 26.163
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : pseudoinverse used at -3.115
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : neighborhood radius 5.115
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : at 1030.1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : radius 26.163
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : There are other near singularities as well. 26.163
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : zero-width neighborhood. make span bigger

## Warning in simpleLoess(y, x, w, span, degree = degree, parametric =
## parametric, : zero-width neighborhood. make span bigger
## Warning: Computation failed in `stat_smooth()`:
## NA/NaN/Inf in foreign function call (arg 5)