#DAY 2: ANALYSIS DIAGRAM
##SIMPLE DIAGRAM
###Task 1: Diagram with hist()
students=read.csv("C:\\Users\\E7450\\Desktop\\R\\Datasets cho thuc hanh CR 8-2019\\PISA VN 2015.csv")
schools=read.csv("C:\\Users\\E7450\\Desktop\\R\\Datasets cho thuc hanh CR 8-2019\\PISA VN SCHOOLS 2015.csv")
pisa=merge(students,schools,by="CNTSCHID")
hist(pisa$PV1SCIE,col="blue")
hist(pisa$PV1SCIE,col="blue",border="white")
hist(pisa$PV1SCIE,col="blue",border="white",xlab="science score",ylab="frequency",main="distribution of science score")
hist(pisa$PV1SCIE,col="blue",border="white",prob=T)
lines(density(pisa$PV1SCIE), col = "red")
p1=hist(pisa$PV1SCIE[pisa$Gender=="Boys"],plot=F)
p2=hist(pisa$PV1SCIE[pisa$Gender=="Girls"],plot=F)
plot(p1,col="skyblue",border="white")
plot(p2,add=T,col=scales::alpha("yellow",0.7),border="green")
###Task 2: Diagram with lattice()
library(lattice)
densityplot(~PV1SCIE,groups=Gender,data=pisa)
densityplot(~PV1SCIE,groups=Area,data=pisa)
densityplot(~PV1SCIE,groups=Area,data=pisa,auto.key=list(space="top"))
p1=densityplot(~PV1SCIE,groups=Area,data=pisa,auto.key=list(space="top"))
p2=densityplot(~PV1MATH,groups=Area,data=pisa)
p3=densityplot(~PV1READ,groups=Area,data=pisa)
library(gridExtra)
grid.arrange(p1,p2,p3,ncol=3)
###Task 3: Barplot with sjPlot
library(sjPlot)
sjPlot::plot_frq(pisa$Area)
sjPlot::plot_frq(pisa$Region)
sjp.xtab(pisa$Region,pisa$Area,margin="row",bar.pos="stack",show.summary = T)
sjp.xtab(pisa$Region,pisa$Area,margin="row",bar.pos="stack",show.summary = T,coord.flip = T)
sjp.grpfrq(pisa$PV1SCIE,pisa$Region,type="box")
## Warning in rq.fit.br(wx, wy, tau = tau, ...): Solution may be nonunique
## Warning in rq.fit.br(wx, wy, tau = tau, ...): Solution may be nonunique
## Warning in rq.fit.br(wx, wy, tau = tau, ...): Solution may be nonunique
###Task 4: Boxplot with boxplot()
par(mfrow=c(1,3))
boxplot(pisa$PV1SCIE,col="purple")
boxplot(pisa$PV1SCIE~pisa$Gender,col=c("blue","red"))
boxplot(pisa$PV1SCIE~pisa$Region,col=c("blue","red","purple"))
###Task 5: Diagram with plot()
plot(pisa$PV1SCIE~pisa$PARED,col="blue")
plot(pisa$PV1SCIE~pisa$PARED,col="blue")
abline(lm(pisa$PV1SCIE~pisa$PARED),col="red")
library(sjPlot)
sjp.grpfrq(pisa$PV1SCIE,pisa$PARED,type="box")
## Warning in rq.fit.br(wx, wy, tau = tau, ...): Solution may be nonunique
###Task 6: Diagram likert
big5=read.csv("C:\\Users\\E7450\\Desktop\\R\\Datasets cho thuc hanh CR 8-2019\\Big Five Personality Data.csv")
test=big5[,c("gender","E1","E2","E3","E4","E5")]
test$E1=as.factor(big5$E1)
test$E2=as.factor(big5$E2)
test$E3=as.factor(big5$E3)
test$E4=as.factor(big5$E4)
test$E5=as.factor(big5$E5)
library(sjPlot)
sjPlot::plot_likert(test)
## Warning: Detected uneven category count in items. Dropping last category.
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length
## Warning in freq[valid] <- counts: number of items to replace is not a
## multiple of replacement length