标签:density and object lib fill number variables datatable rar
diamonds数据结构
carat | cut | color | clarity | depth | table | price | x | y | z | |
---|---|---|---|---|---|---|---|---|---|---|
1
|
0.38
|
Ideal
|
E
|
VS1
|
60.8
|
56.0
|
940
|
4.70
|
4.75
|
2.86
|
2
|
0.30
|
Ideal
|
E
|
VS2
|
61.7
|
55.0
|
658
|
4.30
|
4.32
|
2.66
|
3
|
0.76
|
Very Good
|
G
|
VS2
|
62.1
|
54.0
|
2990
|
5.88
|
5.94
|
3.67
|
4
|
2.02
|
Premium
|
G
|
SI2
|
60.1
|
59.0
|
17099
|
8.29
|
8.21
|
4.96
|
5
|
0.70
|
Premium
|
F
|
SI2
|
58.4
|
61.0
|
1966
|
5.86
|
5.79
|
3.40
|
6
|
1.05
|
Ideal
|
H
|
SI2
|
60.6
|
57.0
|
3234
|
6.59
|
6.55
|
3.98
|
dsmall <- diamonds[sample(nrow(diamonds), 100), ] qplot(carat, price, data = diamonds) ##1.基本aesthetic attributes :colour\shape\size\alpha qplot(carat, price, data = dsmall, colour = color) qplot(carat, price, data = dsmall, shape = cut) qplot(carat, price, data = diamonds, alpha = I(1/10)) ###You can also manually set the aesthetics using I() #####2.geometric object ###2.1 smooth method到底用什么方法 可以加载不同的包 如MASS 按相应的回归formula输入即可 qplot(carat, price, data = dsmall, geom = c("point", "smooth")) #####默认小样本(小于1000)使用局部回归 qplot(carat, price, data = dsmall, geom = c("point", "smooth"),span = 0.2) #span调整平滑程度 library(mgcv) qplot(carat, price, data = dsmall, geom = c("point", "smooth"),method = "gam", formula = y ~ s(x, bs = "cs")) #####默认大样本(大于1000)的回归算法 qplot(carat, price, data = dsmall, geom = c("point", "smooth"),method = "lm") #最小二乘
qplot(color, price / carat, data = diamonds, geom = "jitter",alpha = I(1 / 5)) #第一个参数是分类变量,第二个是连续变量 qplot(cut,price/carat,data=dsmall,geom=c(‘jitter‘,‘boxplot‘),alpha=I(0.5),colour=cut)##jitter boxplot 可以一起用 ##boxplot中colour是外框线颜色,fill是填充颜色,size是线的粗细
qplot(carat, data = diamonds, geom = "histogram", binwidth = 0.01,xlim = c(0,3)) ##histogram默认Y轴为频数 qplot(carat, data = diamonds, geom = "histogram", fill = color) #使用fill参数可以很快得到堆积柱形图 qplot(color, data = diamonds, geom = "bar", weight = carat) +scale_y_continuous("carat") #y轴不再是频数,而是对给定的weight求和,+号后面的代码是变坐标轴名称count为carat
year <- function(x) as.POSIXlt(x)$year + 1900 #as.POSIXlt(x)读取的日期(字符串) 转化为 “Date” 类型数据 qplot(unemploy / pop, uempmed, data = economics,geom = c("point", "path")) qplot(unemploy / pop, uempmed, data = economics,geom = "path", colour =year(date)) + scale_size_area() #按年份更换颜色
标签:density and object lib fill number variables datatable rar
原文地址:http://www.cnblogs.com/winda921/p/7617181.html