可視化分析
數據讀取
設置工作路徑後讀取路徑下的數據
setwd("C:\\Users\\Administrator\\Desktop\\R_visualization")
df<-read.csv("Data.csv", header = TRUE)
數據讀取如下:
學習的數據和代碼路徑爲:
百度雲鏈接:https://pan.baidu.com/s/1Ey99ESQTzjm3O5ggj2OrwQ
提取碼:huni
散點圖
plot(df$SOD, df$tau)#,pch=21,lty=0.25,col="grey10")
直方圖
hist(df$SOD,breaks =30,ylim=c(0,40),main = "")
箱線圖
boxplot(SOD~Class,data=df,xlab="Class",ylab="SOD")
lattice包可視化
library(lattice)
p1<-xyplot(SOD~tau,df,col="black")
p2<-histogram(~SOD,df,type="count",nint=30,col="white")
p3<-bwplot(SOD~Class,df,xlab="Class",
par.settings = canonical.theme(color = FALSE))
library(gridExtra)
grid.arrange(p1,p2,p3, ncol = 3, nrow = 1)
ggplot2繪圖
library(ggplot2)
p1<-ggplot(df, aes(x=SOD,y=tau)) +
geom_point() #shape=21,color="black",fill="red",size=3,stroke=0.1
p2<-ggplot(df, aes(SOD)) +
geom_histogram(bins=30,colour="black",fill="white")
p3<-ggplot(df, aes(x=Class,y=SOD)) +
geom_boxplot()
library(gridExtra)
grid.arrange(p1,p2,p3, ncol = 3, nrow = 1)
參考資料1:https://github.com/EasyChart/Beautiful-Visualization-with-R/
參考資料2:https://blog.csdn.net/tandelin/article/details/87719623