# R语言-白葡萄酒数据集探索

### 查看数据基本情况

data<-read.csv(“/Users/xxx/Desktop/whitewine.csv”,sep=”,”,header = TRUE)

head(data)

class(data)

str(data)

library(mice)

library(VIM)

md.pattern(data)

aggr(data,prop=F,numbers=T)

head()

data<-data[-which(is.na(data[,2])),] aggr(data,prop=F,numbers=T)

### 单变量分析

ggplot(aes(x=quality),data=data) + geom_bar()+scale_x_continuous(lim=c(3,9),breaks = seq(3,9,1))

### 双变量分析

ggplot(data,aes(x=quality,y=density,group=quality))+geom_boxplot()

ylim1<-boxplot.stats(data\$density)\$stats[c(1, 5)]

ggplot(data = data,aes(x=quality,y=density,group=quality))+geom_boxplot()+

coord_cartesian(ylim = ylim1)

### 多变量分析

ggplot(aes(x = alcohol, y = density, color = factor(quality)), data = data) +

geom_jitter(alpha = 0.2) +

scale_color_brewer(palette = “Blues”) +

geom_smooth(method = “lm”, se = FALSE,size=1) +

ylim(0.985, 1.005) +

labs(y = ‘Density’,x = ‘Alcohol’) +

ggtitle(“density VS alcohol VS quality”)

ggplot(data,aes(x=alcohol,y=density,colour=factor(quality)))+geom_point()+facet_wrap(~quality)

6.1日更：最近事多没上简书，忽然发现好多人要数据集。