Part 1

  1. Nominal: Sex, Race, School Type, High School Program,
  2. Ordinal: Socioeconomic Status
  3. Numerical: ID, Reading score, writing score, math score, science score and civics score.
library("foreign")
hsbdata=read.spss("hsb.sav")
str(hsbdata)
## List of 15
##  $ ID    : num [1:600] 1 2 3 4 5 6 7 8 9 10 ...
##  $ SEX   : num [1:600] 2 1 2 2 2 1 1 2 1 2 ...
##  $ RACE  : num [1:600] 2 2 2 2 2 2 2 2 2 2 ...
##  $ SES   : num [1:600] 1 1 1 2 2 2 1 1 2 1 ...
##  $ SCTYP : num [1:600] 1 1 1 1 1 1 1 1 1 1 ...
##  $ HSP   : num [1:600] 3 2 2 3 3 2 1 1 1 1 ...
##  $ LOCUS : num [1:600] 0.29 -0.42 0.71 0.06 0.22 0.46 0.44 0.68 0.06 0.05 ...
##  $ CONCPT: num [1:600] 0.88 0.03 0.03 0.03 -0.28 0.03 -0.47 0.25 0.56 0.15 ...
##  $ MOT   : num [1:600] 0.67 0.33 0.67 0 0 0 0.33 1 0.33 1 ...
##  $ CAR   : num [1:600] 10 2 9 15 1 11 10 9 9 11 ...
##  $ RDG   : num [1:600] 33.6 46.9 41.6 38.9 36.3 49.5 62.7 44.2 46.9 44.2 ...
##  $ WRTG  : num [1:600] 43.7 35.9 59.3 41.1 48.9 46.3 64.5 51.5 41.1 49.5 ...
##  $ MATH  : num [1:600] 40.2 41.9 41.9 32.7 39.5 46.2 48 36.9 45.3 40.5 ...
##  $ SCI   : num [1:600] 39 36.3 44.4 41.7 41.7 41.7 63.4 49.8 47.1 39 ...
##  $ CIV   : num [1:600] 40.6 45.6 45.6 40.6 45.6 35.6 55.6 55.6 55.6 50.6 ...
##  - attr(*, "label.table")=List of 15
##   ..$ ID    : NULL
##   ..$ SEX   : NULL
##   ..$ RACE  : NULL
##   ..$ SES   : NULL
##   ..$ SCTYP : NULL
##   ..$ HSP   : NULL
##   ..$ LOCUS : NULL
##   ..$ CONCPT: NULL
##   ..$ MOT   : NULL
##   ..$ CAR   : NULL
##   ..$ RDG   : NULL
##   ..$ WRTG  : NULL
##   ..$ MATH  : NULL
##   ..$ SCI   : NULL
##   ..$ CIV   : NULL
##  - attr(*, "codepage")= int 28591

Part 2

Barplot

library("ggplot2")
Table1=table(hsbdata$SEX)
dede=as.data.frame(Table1)
names(dede)=c("sex","frequency")
sexdata=ggplot(data=dede,aes(x=sex,y=frequency))
sexbar=sexdata+geom_bar(stat = "identity")
sexbar

titlename="sex freqency"
sourcename="High School and Beyond Dataset"
sexbar2=sexbar+labs(title = titlename,caption = sourcename)
sexbar2

sexbar3=sexbar+geom_bar(stat = "identity",fill="white")+labs(title = titlename,caption = sourcename)+theme(plot.title = element_text(hjust = 0.5))
sexbar3

Part 3

Boxplot

sesdata=ggplot(as.data.frame(hsbdata),aes(x=as.factor(SES),y=as.numeric(MATH)))
titlename1="Mathscore-Socieconomic Status"
SESplot=sesdata+geom_boxplot()+labs(title = titlename1,caption = sourcename)
SESplot

SESplot2=SESplot+theme(plot.title = element_text(hjust = 0.5))
SESplot2

Part 4

Histogram

Readingscore=ggplot(as.data.frame(hsbdata),aes(x=RDG))
titlename2="Reading SCORE"
RDGTABLE=Readingscore+geom_histogram()+labs(title = titlename2,caption = sourcename)
RDGTABLE
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

RDGTABLE2=RDGTABLE+stat_bin(binwidth = 2)
RDGTABLE2
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Part 5

Alternative

sexpoint=sexdata+geom_point()
sexpoint

pie(table(hsbdata$SEX))

RDGV.S.MATH=ggplot(as.data.frame(hsbdata),aes(x=as.numeric(RDG),y=as.numeric(MATH)))+geom_point()
RDGV.S.MATH

Part 6

setwd("C:/Users/xwb/Desktop/Data\ Analysis")
library("readxl")
transactiondat=read_excel("Transaction.xlsx")
Transactiontable=as.data.frame(transactiondat)
Transactiontable[1,1]=4.15
Transactiontable[5,1]=4.19
Transactiontable
##    Date Transaction
## 1  4.15        4.00
## 2  4.16       48.00
## 3  4.17        0.00
## 4  4.18        8.80
## 5  4.19       46.78
## 6  4.20       40.00
## 7  4.21      119.00
## 8  4.22        0.00
## 9  4.23        4.80
## 10 4.24        0.00
## 11 4.25        7.35
## 12 4.26       45.80
## 13 4.27       54.00
## 14 4.28        0.00
Transactiontable$Date=as.character(Transactiontable$Date)
Transactiontable$Transaction=as.numeric(Transactiontable$Transaction)
p = ggplot(Transactiontable, aes(x = Transactiontable$Date, y = Transactiontable$Transaction, group = 1))
pline=p + geom_line() + geom_point()
pline