data visualization - muic math › _media › data_visualization.pdf · 2018-10-02 · load and...
TRANSCRIPT
![Page 1: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/1.jpg)
DATA VISUALIZATIONCHATCHAWAN PANRAKSAMUIC
![Page 2: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/2.jpg)
ggplot2
#Data Visualization#Install ggplot2install.packages("ggplot2")library(ggplot2)
#Install pscl packageinstall.packages("pscl")library(pscl)
![Page 3: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/3.jpg)
Load and view data
#DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit admit=admit View(admit)
![Page 4: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/4.jpg)
Histogram ggplot(admit,aes(gre.quant))
![Page 5: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/5.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram() #NOTE Run=Ctrl+Enter #We can copy quicker by “ExportCopy to
ClipboardCopy PlotCtrl+V”
![Page 6: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/6.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth= 10)
![Page 7: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/7.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth= 50)
![Page 8: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/8.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50)+ggtitle("Distribution of GRE Quant")
![Page 9: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/9.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50)+ggtitle("Distribution of GRE Quant")+ylab("Frequency")
![Page 10: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/10.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50)+ggtitle("Distribution of GRE Quant")+ylab("Frequency")+xlab("GRE Quantitative Test")
![Page 11: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/11.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50)+ggtitle("Distribution of GRE Quant")+ylab("Frequency")+xlab("GRE Quantitative Test")+xlim(0,1000)
![Page 12: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/12.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50,color="red")+ggtitle("Distribution of GRE Quant")+ylab("Frequency")+xlab("GRE Quantitative Test")+xlim(0,1000)
![Page 13: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/13.jpg)
ggplot(admit,aes(gre.quant))+geom_histogram(binwidth = 50,color="red",fill="green")+ggtitle("Distribution of GRE Quant")+ylab("Frequency")+xlab("GRE Quantitative Test")+xlim(0,1000)
![Page 14: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/14.jpg)
Scatter Plot ggplot(admit,aes(x=gre.quant,y=gre.verbal))
![Page 15: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/15.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal))+geom_point()
![Page 16: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/16.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal))+geom_point()+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 17: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/17.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal))+geom_point(size=5)+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 18: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/18.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal))+geom_point(size=5,color="blue")+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 19: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/19.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal,color=score))+geom_point(size=5,color="blue")+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 20: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/20.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal,color=as.character(score)))+geom_point(size=5,color="blue")+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 21: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/21.jpg)
ggplot(admit,aes(x=gre.quant,y=gre.verbal,color=as.character(score)))+geom_point(size=5)+ggtitle("Correlation of GRE Quant and GRE Verbal")
![Page 22: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/22.jpg)
Correlation Analysis #Sum of gre.quant and gre.verbal ss<-admit$gre.quant+admit$gre.verbal ggplot(admit,aes(x=ss,y=score))+geom_point(size=5)+ggtitle("Correl
ation of wt and mpg") mean(ss)
![Page 23: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/23.jpg)
ggplot(admit,aes(x=ss,y=score))+geom_point(size=5)+ggtitle("Correlation of ss and Score")
#NOTE It is NOT a real correlation!
![Page 24: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/24.jpg)
Correlation Analysis
cor(admit$gre.verbal,admit$gre.quant)[1] 0.1599913 cor(admit$gre.verbal,admit$score) Error in cor(admit$gre.verbal, admit$score) : 'y' must be numeric #NOTE “score” is an ordinal data.
![Page 25: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/25.jpg)
Box Plot ggplot(admit,aes(x=score,y=gre.quant))+geom_boxplot()
![Page 26: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/26.jpg)
ggplot(admit,aes(x=as.character(score),y=gre.quant))+geom_boxplot()+xlab("Score")+ggtitle("Boxplots for GRE Quantitive Test")
![Page 27: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/27.jpg)
ggplot(admit,aes(x=as.character(score),y=gre.quant,color=as.character(score)))+geom_boxplot()+xlab("Score")+ggtitle("Boxplots for GRE Quantitive Test")
![Page 28: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/28.jpg)
ggplot(admit,aes(x=as.character(score),y=gre.quant,color=as.character(score),fill=as.character(score)))+geom_boxplot()+xlab("Score")+ggtitle("Boxplots for GRE Quantitive Test")
![Page 29: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/29.jpg)
Some more plots: Violin Plot ggplot(admit,aes(x=as.character(score),y=gre.quant,color=as.char
acter(score),fill=as.character(score)))+geom_violin()+xlab("Score")+ggtitle("Boxplots for GRE Quantitive Test")
![Page 30: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/30.jpg)
Some More Plots: “plotly” package
#Install Plotly install.packages("plotly") library(plotly)
![Page 31: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/31.jpg)
“plotly” package aa<-admit[sample(nrow(admit),100),] plot_ly(aa,x=~gre.quant,y=~gre.verbal,color=~score,size=~gre.verba
l,text=~paste("ap",ap))
![Page 32: DATA VISUALIZATION - MUIC Math › _media › data_visualization.pdf · 2018-10-02 · Load and view data #DATA data() #Load Data mtcars mtcars=mtcars View(mtcars) #Load Data admit](https://reader034.vdocuments.us/reader034/viewer/2022042401/5f10523a7e708231d44887e7/html5/thumbnails/32.jpg)
#Plotly d<-diamonds[sample(nrow(diamonds),1000),] plot_ly(d,x=~carat,y=~price,color=~carat,size=~carat,text=~paste("
Clarity",clarity))