数据读取
设置工作路径后读取路径下的数据
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