R数据可视化实验报告
一、实验目的与要求
1.掌握基本绘图系统、Lattice绘图系统、ggplot2绘图系统。
2.学会绘制散点图,条形图,箱线图。
3.了解其他功能多样的可视化图形如:脸谱图、韦恩图。
二、设备与环境
软件环境: Windowns 7;R-3.6.3
实验指导书:《大数据挖掘实验教程》。
三、实验内容(具体的表内容参照实验指导书)
- 使用基本绘图系统graphics包绘制图形
- 使用Lattice绘图系统中lattice包和grid包绘制图形
- 使用ggplot2绘图系统绘制图形
- 绘制脸谱图、韦恩图
四、实验过程与结果
1.使用基本绘图系统graphics包绘制图形
install.packages("graphics")
library("graphics")
plot(x=iris$Sepal.Length,y=iris$Sepal.Width,pch=19,cex=0.8,frame=FALSE,xlab="Sepal Length",ylab="Sepal Width")
2.使用Lattice绘图系统中lattice包和grid包绘制图形
> install.packages("lattice")
> library("lattice")
> xyplot(Temp~Ozone,data=airquality)
> airquality$Month<-factor(airquality$Month)
> xyplot(Temp~Ozone|Month,data=airquality,layout=c(5,1))
3.
> install.packages("ggplot2")
> library("ggplot2")
> install.packages("gcookbook")
> library(gcookbook)
> heightweight[1:5,c("ageYear","heightIn")]
ageYear heightIn
1 11.92 56.3
2 12.92 62.3
3 12.75 63.3
4 13.42 59.0
5 15.92 62.5
> ggplot(heightweight,aes(x=ageYear,y=heightIn,shape=sex,))+geom_point(shape=19,size=3.5,alpha=5)
> require(ggplot2)
> data("diamonds")
> set.seed(42)
> small<-diamonds[sample(nrow(diamonds),1000),]
> head(small)
# A tibble: 6 x 10
carat cut color clarity depth table price x y z
<dbl> <ord> <ord> <ord> <dbl> <dbl> <int> <dbl> <dbl> <dbl>
1 0.39 Ideal I VVS2 60.8 56 849 4.74 4.76 2.89
2 1.12 Very Good G SI2 63.3 58 4478 6.7 6.63 4.22
3 0.51 Very Good G VVS2 62.9 57 1750 5.06 5.12 3.2
4 0.52 Very Good D VS1 62.5 57 1829 5.11 5.16 3.21
5 0.28 Very Good E VVS2 61.4 55 612 4.22 4.25 2.6
6 1.01 Fair F SI1 67.2 60 4276 6.06 6 4.05
> ggplot(small)+geom_bar(aes(x=clarity,fill=cut))+coord_polar()
4.
> install.packages("aplpack")
> library("aplpack")
> data("longley")
> faces(longley[1:9,],face.type=1)
effect of variables:
modified item Var
"height of face " "GNP.deflator"
"width of face " "GNP"
"structure of face" "Unemployed"
"height of mouth " "Armed.Forces"
"width of mouth " "Population"
"smiling " "Year"
"height of eyes " "Employed"
"width of eyes " "GNP.deflator"
"height of hair " "GNP"
"width of hair " "Unemployed"
"style of hair " "Armed.Forces"
"height of nose " "Population"
"width of nose " "Year"
"width of ear " "Employed"
"height of ear " "GNP.deflator"
> library(VennDiagram)
> A<-sample(LETTERS,18,replace = FALSE)
> B<-sample(LETTERS,20,replace = FALSE)
> C<-sample(LETTERS,22,replace = FALSE)
> D<-sample(LETTERS,19,replace = FALSE)
> venn.diagram(x=list(A=A,D=D,B=B,C=C),filename = "icebns.png",height=450,width=450,resolution = 300,imagetype = "png",col="transparent",fill=c("cornflowerblue","green","yellow","darkorchid"),alpha=0.50,cex=0.45,cat.cex=0.45)