R語言可視化(一)

可視化分析

數據讀取

設置工作路徑後讀取路徑下的數據

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

發佈了269 篇原創文章 · 獲贊 67 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章