上文为大家介绍的是R语言中的理解关键制图参数,相信大家已经对R语言有一定的了解了,接下来小编就给大家说说关于散点图。
一、利用xyplot()对散点分组
library(lattice)
xyplot(mpg~disp,
data=mtcars,
groups=cyl,
auto.key=list(corner=c(1,1)))
二、使用散点形状和大小来表示分组
qplot(disp,mpg,data=mtcars,shape=as.factor(cyl))
qplot(disp,mpg,data=mtcars,size=as.factor(cyl))
三、用text()标识点
health<-read.csv("HealthExpenditure.csv",header=TRUE)
plot(health$Expenditure,health$Life_Expectancy,type="n")
text(health$Expenditure,health$Life_Expectancy,health$Country)
四、误差条
arrows(x0=mtcars$disp*0.95,
y0=mtcars$mpg,
x1=mtcars$disp*1.05,
y1=mtcars$mpg,
angle=90,
code=3,
length=0.04,
lwd=0.4)
五、jitter()
plot(jitter(x), jitter(y))
Jitter函数:给向量加上,少许噪音
六、非线性模型的拟合曲线
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")
七、三维散点图
scatterplot3d(mtcars$wt,mtcars$di
sp,mtcars$mpg,
pch=16, highlight.3d=TRUE,
angle=20,
xlab="Weight",ylab="Displacemen
t",zlab="Fuel Economy (mpg)",
type="h",
main="Relationships between car
specifications")
八、线性回归模型的检验
lmfit<-lm(mtcars$mpg~mtcars$disp)
par(mfrow=c(2,2))
plot(lmfit)
关于R语言数据展现——散点图的讲述就到这里了,上述的内容只是截取了资料中的一部分,如需获取完整的资料,可通过关注微信公众号后联系客服获取。
想要了解更多的资料、信息,可持续关注我们,我们将为大家提供有价值、有需求的材料。为大家在整理数据时省去烦恼。