#set wd 
setwd("~/NYU/classes/2. R/Assignments/Lesson 5")
library(readr)
View(attitude)

#Task # 1 - Produce at least one scatter plot, histogram, and box-and-whisker plot for each variable. Complete this as a R Markdown document.

#rating 

#scatter plot
plot(attitude$rating, type="p", frame.plot=FALSE, ylab = "rating", col="Red", main = "Attitude - Rating")

#Histogram 
hist(attitude$rating, breaks=10, main = "Attitude - rating", xlab="Rating", col="Red", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$rating, main = "Attitude - rating", ylab = "Rating", col="Red")

#Complaints 

#scatter plot
plot(attitude$complaints, type="p", frame.plot=FALSE, ylab = "compaints", col="Blue", main = "Attitude - Rating")

#Histogram 
hist(attitude$complaints, breaks=10, main = "Attitude - compaints", xlab="Rating", col="Blue", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$complaints, main = "Attitude - compaints", ylab = "Rating", col="Blue")

#privileges 

#scatter plot
plot(attitude$privileges, type="p", frame.plot=FALSE, ylab = "privileges", col="Green", main = "Attitude - Rating")

#Histogram 
hist(attitude$privileges, breaks=10, main = "Attitude - privileges", xlab="Rating", col="Green", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$privileges, main = "Attitude - privileges", ylab = "Rating", col="Green")

#learning 

#scatter plot
plot(attitude$learning, type="p", frame.plot=FALSE, ylab = "learning", col="Purple", main = "Attitude - Rating")

#Histogram 
hist(attitude$learning, breaks=10, main = "Attitude - learning", xlab="Rating", col="Purple", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$learning, main = "Attitude - learning", ylab = "Rating", col="Purple")

#raises 

#scatter plot
plot(attitude$raises, type="p", frame.plot=FALSE, ylab = "raises", col="Orange", main = "Attitude - Rating")

#Histogram 
hist(attitude$raises, breaks=10, main = "Attitude - raises", xlab="Rating", col="Orange", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$raises, main = "Attitude - raises", ylab = "Rating", col="Orange")

#critical 

#scatter plot
plot(attitude$critical, type="p", frame.plot=FALSE, ylab = "critical", col="Brown", main = "Attitude - Rating")

#Histogram 
hist(attitude$critical, breaks=10, main = "Attitude - critical", xlab="Rating", col="Brown", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$critical, main = "Attitude - critical", ylab = "Rating", col="Brown")

#advance 

#scatter plot
plot(attitude$advance, type="p", frame.plot=FALSE, ylab = "advance", col="Gray", main = "Attitude - Rating")

#Histogram 
hist(attitude$advance, breaks=10, main = "Attitude - advance", xlab="indigo", col="Gray", labels=TRUE, border="#FFFFFF")

#box-and-whisker
boxplot(attitude$advance, main = "Attitude - advance", ylab = "indigo", col="Gray")

#Combined Histograms

par(mfrow=c(3,4))
hist(attitude$rating, breaks=5, main = "Attitude - rating", xlab="Rating", col="Red", labels=TRUE, border="#FFFFFF")
hist(attitude$complaints, breaks=5, main = "Attitude - compaints", xlab="Rating", col="Blue", labels=TRUE, border="#FFFFFF")
hist(attitude$privileges, breaks=5, main = "Attitude - privileges", xlab="Rating", col="Green", labels=TRUE, border="#FFFFFF")
hist(attitude$learning, breaks=5, main = "Attitude - learning", xlab="Rating", col="Purple", labels=TRUE, border="#FFFFFF")
hist(attitude$raises, breaks=5, main = "Attitude - raises", xlab="Rating", col="Orange", labels=TRUE, border="#FFFFFF")
hist(attitude$critical, breaks=5, main = "Attitude - critical", xlab="Rating", col="Brown", labels=TRUE, border="#FFFFFF")
hist(attitude$advance, breaks=5, main = "Attitude - advance", xlab="Rating", col="Gray", labels=TRUE, border="#FFFFFF")

#Task#2 - Undergrad Data

##Use the undersgraduate survey data from http://becomingvisual.com/rfundamentals/undergrad.csv to create ordered factor variables for the excel, statistics and programming variables. Draw histograms for your new ordered factor variables.

#import the data 
library(readr)
undergrad=read_csv("undergrad.csv")
## Rows: 39 Columns: 11
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (8): Timestamp, The following tools are important to my future career. [...
## dbl (3): How likely are you to take another information systems course at St...
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
#rename the data 
names(undergrad) <- c("timestamp","excel","access", "statistics", "programming", "iscourse", "cscourse", "topics", "istopics", "onlinecourse", "concentration")
names(undergrad)
##  [1] "timestamp"     "excel"         "access"        "statistics"   
##  [5] "programming"   "iscourse"      "cscourse"      "topics"       
##  [9] "istopics"      "onlinecourse"  "concentration"
#Create ordered factored variables 

#excel
table(undergrad$excel)
## 
##          Agree Somewhat agree Strongly Agree 
##              9              3             27
undergrad_excel=ordered(x=undergrad$excel, levels = c("Disagree", "Somewhat disagree", "Neither agree or disagree", "Somewhat agree", "Agree", "Strongly Agree"))
class(undergrad_excel)
## [1] "ordered" "factor"
#statistics
table(undergrad$statistics)
## 
##                     Agree                  Disagree Neither agree or disagree 
##                        13                         1                         2 
##            Somewhat agree            Strongly Agree 
##                         7                        15
undergrad_stats=ordered(x=undergrad$statistics, levels = c("Disagree", "Somewhat disagree", "Neither agree or disagree", "Somewhat agree", "Agree", "Strongly Agree"))
class(undergrad_stats)
## [1] "ordered" "factor"
#programming
table(undergrad$programming)
## 
##                     Agree                  Disagree Neither agree or disagree 
##                        12                         1                         5 
##            Somewhat agree         Somewhat disagree            Strongly Agree 
##                         6                         2                        13
undergrad_prog=ordered(x=undergrad$programming, levels = c("Disagree", "Somewhat disagree","Neither agree or disagree", "Somewhat agree", "Agree", "Strongly Agree"))
class(undergrad_prog)
## [1] "ordered" "factor"
#create Historgrams
par(mfrow=c(1,3))
hist(as.numeric(undergrad_excel), breaks=8, main = "Excel", xlab="Excel", col="Red", labels=TRUE, border="#FFFFFF")
hist(as.numeric(undergrad_stats), breaks=8, main = "Statistics", xlab="Statistics", col="Blue", labels=TRUE, border="#FFFFFF")
hist(as.numeric(undergrad_prog), breaks=8, main = "Programming", xlab="Programming", col="Green", labels=TRUE, border="#FFFFFF")