
上QQ阅读APP看书,第一时间看更新
2.5 R的数据绘图
用R函数包“ggplot2”的数据集“diamonds”钻石,来说明R的数据绘图。
钻石数据
钻石数据是数据框的结构,有53940行(样本),10列(变量):
(1)价格Price美金$326--$18,823
(2)克拉Carat质量0.2--5.01
(3)切割Cut Fair,Good,Very Good,Premium,Ideal
(4)色泽Color J(worst)to D(best)
(5)净度Clarity I1(worst),SI2,SI1,VS2,VS1,VVS2,VVS1,IF(best)
(6)长 X length in mm(0--10.74)
(7)宽 Y width in mm(0--58.9)
(8)高 Z depth in mm(0--31.8)
(9)深度 Depth = z / mean(x,y)= 2 * z /(x + y)(43--79)
(10)形状Table = top of diamond relative to widest point(43--95)
【R例2.1】钻石数据:diamonds,函数{包}:qplot ggplot {ggplot2}

如图2-10~图2-15所示。

图2-10 钻石价格直方图

图2-11 钻石价格和切割箱线图

图2-12 钻石克拉和切割小提琴图

图2-13 钻石价格和净度箱线图

图2-14 钻石变量相关系数1

图2-15 钻石变量相关系数2