可视化-鸢尾花

2017-03-19  本文已影响0人  potherb

R语言:

需要使用包:绘图包ggplot2、gridExtra(图形分布)、GGally(ggplot扩展,适合做成对出现图形)

library(ggplot2)

library(gridExtra)

#加载数据

iris=read.csv('../input/Iris.csv')

View(iris)

ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, colour=Species, shape=Species)) + geom_point()

ggplot(iris, aes(Species, Petal.Length, fill=Species)) + geom_boxplot()

HisSl <- ggplot(data=iris, aes(x=Sepal.Length))+

geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +

theme(legend.position="none")+

ggtitle("Histogram of Sepal Length")

HistSw <- ggplot(data=iris, aes(x=Sepal.Width)) +

geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +

theme(legend.position="none")+

ggtitle("Histogram of Sepal Width")

HistPl <- ggplot(data=iris, aes(x=Petal.Length))+

geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +

theme(legend.position="none")+

ggtitle("Histogram of Petal Length")

HistPw <- ggplot(data=iris, aes(x=Petal.Width))+

geom_histogram(binwidth=0.2, color="black", aes(fill=Species)) +

theme(legend.position="bottom" )+

ggtitle("Histogram of Petal Width")

grid.arrange(HisSl,HistSw,HistPl,HistPw,nrow = 2,top = textGrob("Iris Frequency Histogram",gp=gpar(fontsize=15)))

ggpairs(data = iris[1:4],title = "Iris Correlation Plot")


python:

三个依赖库:pandas(pandas 是基于 Numpy 构建的含有更高级数据结构和工具的数据分析包)、seaborn(Seaborn是在matplotlib的基础上进行了更高级的API封装,从而使得作图更加容易)、matplotlib(python一个强大的绘图库)

import pandas as pd

import warnings

import seaborn as sns

import matplotlib.pyplot as plt

#读入数据

iris=pd.read_csv("../input/Iris.csv")

iris.head()

iris["Species"].value_counts()

iris.plot(kind="scatter",x="SepalLengthCm",y="SepalWidthCm")

plt.show()

sns.jointplot(x="SepalLengthCm",y="SepalWidthCm",data=iris,size=5)

sns.FacetGrid(iris, hue="Species", size=5) \    .map(plt.scatter, "SepalLengthCm", "SepalWidthCm") \    .add_legend()

ax=sns.stripplot(x="Species",y="PetalLengthCm",data=iris,jitter=True,edgecolor="gray")

sns.pairplot(iris.drop("Id", axis=1), hue="Species", size=3)

knime:

通过csv reader读入iris文件。然后在analytics下的statistics下选择对应的可视化展现

SPSS statistics:

导入数据

上一篇下一篇

猜你喜欢

热点阅读