#1、基本要素
#数据(Data)和映射(Mapping)
#几何对象(Geometric)
#标尺(Scale)
#统计变换(Statistics)
#坐标系统(Coordinante)
#图层(Layer)
#分面(Facet)
#主题(Theme)
#2、数据和映射
require(ggplot2)
data(diamonds)
set.seed(42)
#在一个数据框里进行抽样1000行数据
small<-diamonds[sample(nrow(diamonds),1000),]
head(small)
length(small)#给出的时small的列数而不是行数
p<-ggplot(data=small,mapping=aes(x=carat,y=price))
p+geom_point()
#用一个类别因子指定图形类别分组用shape=
p <- ggplot(data=small, mapping=aes(x=carat, y=price, shape=cut))
p+geom_point()
#映射颜色colour
p <- ggplot(data=small, mapping=aes(x=carat, y=price, shape=cut, colour=color))
p+geom_point()
#3、几何对像
#ggplot2支持图层,我通常把不同的图层中共用的映射提供给ggplot函数
#而某一几何对象才需要的映射参数提供给geom_xxx函数。
ggplot(small)+geom_histogram(aes(x=price))
#填充颜色
ggplot(small)+geom_histogram(aes(x=price, fill=cut))
#side-by-s
#数据(Data)和映射(Mapping)
#几何对象(Geometric)
#标尺(Scale)
#统计变换(Statistics)
#坐标系统(Coordinante)
#图层(Layer)
#分面(Facet)
#主题(Theme)
#2、数据和映射
require(ggplot2)
data(diamonds)
set.seed(42)
#在一个数据框里进行抽样1000行数据
small<-diamonds[sample(nrow(diamonds),1000),]
head(small)
length(small)#给出的时small的列数而不是行数
p<-ggplot(data=small,mapping=aes(x=carat,y=price))
p+geom_point()
#用一个类别因子指定图形类别分组用shape=
p <- ggplot(data=small, mapping=aes(x=carat, y=price, shape=cut))
p+geom_point()
#映射颜色colour
p <- ggplot(data=small, mapping=aes(x=carat, y=price, shape=cut, colour=color))
p+geom_point()
#3、几何对像
#ggplot2支持图层,我通常把不同的图层中共用的映射提供给ggplot函数
#而某一几何对象才需要的映射参数提供给geom_xxx函数。
ggplot(small)+geom_histogram(aes(x=price))
#填充颜色
ggplot(small)+geom_histogram(aes(x=price, fill=cut))
#side-by-s