全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2447 2
2015-04-28

第十一章中级绘图

本章内容

二元变量和多元变量关系的可视化

绘制散点图和折线图

理解相关图

学习马赛克图和关联图

本章用到的函数有:

plot

hexbin

ablines

iplot

scatterplot  

scatterplot3d

pairs  

plot3d  

scatterplotMatrix  

scatter3d

cpairs

symbols

smoothScatter


11.1散点图

添加了最佳拟合曲线的散点图

> attach(mtcars)

> plot(wt,mpg,main="Basic Scatter plot of MPGvs.weight",xlab="car weight (lbs/1000",ylab="miles pergallon",pch=19)

>abline(lm(mpg~wt),col="red",lwd=2,lty=1)#添加最佳拟合的线性直线

>lines(lowess(wt,mpg),col="blue",lwd=2,lty=2)#添加一条平滑曲线


car包中的scatterplot()函数增强了散点图的许多功能,它可以很方便地绘制散点图,并

能添加拟合曲线、边界箱线图和置信椭圆,还可以按子集绘图和交互式地识别点。

> library(car)

> scatterplot(mpg~wt|cyl,data=mtcars,lwd=2,

+ main="scatter plot of pmg \n vs. weight by #cylinders",

+ xlab="car weight (lbs/1000)",

+ ylab="miles per gallon",

+ legend.plot=TRUE,#左上边界添加图例

+ id.method="identify",

+ labels=row.names(mtcars),#可通过点的行名称来识别点

+ boxplots="xy"

+ )



11.1.1 散点图矩阵

pairs()函数可以创建基础的散点图矩阵。

> pairs(~mpg+disp+drat+wt,data=mtcars,

+ main="basic scatter plot matrix")


主对角线的上方和下方的六幅散点图是相同的,选项upper.panel =NULL将只生成下三角的图形。

car包中的scatterplotMatrix()函数也可以生成散点图矩阵,并有以下可选操作:

以某个因子为条件绘制散点图矩阵;

包含线性和平滑拟合曲线;

在主对角线放置箱线图、密度图或者直方图;

在各单元格的边界添加轴须图。

> library(car)

> scatterplotMatrix(~mpg+disp+drat+wt,data=mtcars,spread=FALSE,

+ lty.smooth=2,main="scatter plot matrix via car package")

线性和平滑(loess)拟合曲线被默认添加,主对角线处添加了核密度曲线和轴须图。spread = FALSE选项表示不添加展示分散度和对称信息的直线,lty.smooth =2设定平滑(loess)拟合曲线使用虚线而不是实线。


scatterplotMatrix()函数的另一个用法

> library(car)#主对角线的核密度曲线改成了直方图,并且直方图是以各车的气缸数为条件绘制的。

> scatterplotMatrix(~mpg+disp+drat+wt|cyl,data=mtcars,spread=FALSE,

+                  diagonal="histogram",main="scatter plot matrix via carpackage")


由于字数限制  下半部分

传送:https://bbs.pinggu.org/thread-3687472-1-1.html


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-4-28 21:24:28
有没有前面的系列呀,从1开始的
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2015-4-28 22:35:29
moretc 发表于 2015-4-28 21:24
有没有前面的系列呀,从1开始的
https://bbs.pinggu.org/home.php?m ... w=me&from=space
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群