R语言----绘图学习笔记之Scatter plots

原文地址为: R语言----绘图学习笔记之Scatter plots

前言

  最近某项目要搞数据挖掘,需要对数据进行可视化显示,原本我是打算直接用excel 算了,打算,用了一段时间,发现有些数据图用excel麻烦得要命,然后,上网找了一下,原来,有在这方面也有一门专门的语言----R语言,我发现,用它绘制数据图十分强大,就打算花几天,就学习如何用R语言绘制数据图

散布图(scatter plots)

需要掌握的命令:

plot()

xyplot()

qplot()

text()

smoothScatter()

matrix()

jitter()

rbinom()

rnorm()

lines()

lowess()

nls()

用的的包:

ggplot2

lattice

scattersplot3d

帮助用法:

命令行里面直接打

?你要查的命令即可

基础用法:

plot(cars$dist~cars$speed)

image

更多用法在R控制台中打上

?plot

你就清楚用法了

xyplot

数据汇总方法

xyplot(Sepal.Length~Sepal.Width,data=iris,groups=Species,auto.key=list(corner=c(1,1)))

image

格栅

qplot()

qplot(Sepal.Length,Sepal.Width,data=iris,col=as.factor(Species),size=as.factor(Species),shape=as.factor(Species))

image

标识点

plot(mpg~disp,data=mtcars)
text(160,21,"Mazdz RX4")

image

抖动(jitter)

x <- rbinom(1000, 10, 0.25)
y <- rbinom(1000, 10, 0.25)
plot(x, y)

image

抖动后

plot(jitter(x),jitter(y))

image

x所有点都可以显示出来

直线模式:

plot(mtcars$mpg~mtcars$disp)
lmfit <- lm(mtcars$mpg~mtcars$disp)
abline(lmfit)

image

非线性模式的曲线:

x <- -(1:100)/10
y <- 100+10*exp(x/2)+rnorm(x)/10
nlmod <- nls(y~Const+A*exp(B*x),trace=TRUE)
plot(x,y)
lines(x,predict(nlmod),col="red")

image

非参数值的曲线(英文是non-parametric,我也搞不清楚这样了解对不对)

plot(cars, main="测试lowess")
lines(lowess(cars), col="red")
lines(lowess(cars, f=0.3), col="blue")

image

制作3D视图

需要使用 scattersplot3d 包

scatterplot(mtcars$wt, mtcars$disp, mtcars$mpg)

image

QQ图(研究正态分布的一种图…)

qqnorm(mtcars$mpg)
qqline(mtcars$mpg)

image

在坐标轴上显示数据密度

x <- rnorm(1000)
plot(density(x))
rug(x)

image

大数据的平滑分散图显示

n <- 1000000
x <- matrix(rnorm(n), ncol=2)
y <- matrix(rnorm(n,mean=3,sd=1.5), ncol=2)
smoothScatter(x,y)

image

这么看正态分布图挺带感的

资源检索

http://addictedtor.free.fr/graphiques/


转载请注明本文地址: R语言----绘图学习笔记之Scatter plots

猜你喜欢

转载自blog.csdn.net/a13036139941/article/details/81122121