R语言数据展现——散点图

2018.11.15 16:23
1288 0 0

  上文为大家介绍的是R语言中的理解关键制图参数,相信大家已经对R语言有一定的了解了,接下来小编就给大家说说关于散点图。

  一、利用xyplot()对散点分组

  library(lattice)

  xyplot(mpg~disp,

  data=mtcars,

  groups=cyl,

  auto.key=list(corner=c(1,1)))

利用xyplot()对散点分组.png

  二、使用散点形状和大小来表示分组

  qplot(disp,mpg,data=mtcars,shape=as.factor(cyl))

  qplot(disp,mpg,data=mtcars,size=as.factor(cyl))

散点形状和大小.png

  三、用text()标识点

  health<-read.csv("HealthExpenditure.csv",header=TRUE)

  plot(health$Expenditure,health$Life_Expectancy,type="n")

  text(health$Expenditure,health$Life_Expectancy,health$Country)

散点形状和大小.png

  四、误差条

  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)

误差条.png

  五、jitter()

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

  Jitter函数:给向量加上,少许噪音

Jitter函数图.png

  六、非线性模型的拟合曲线

  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")

非线性模型的拟合曲线.png

  七、三维散点图

  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")

三维散点图.png

  八、线性回归模型的检验

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

  par(mfrow=c(2,2))

  plot(lmfit)

线性回归模型的检验.png

  关于R语言数据展现——散点图的讲述就到这里了,上述的内容只是截取了资料中的一部分,如需获取完整的资料,可通过关注微信公众号后联系客服获取。

  想要了解更多的资料、信息,可持续关注我们,我们将为大家提供有价值、有需求的材料。为大家在整理数据时省去烦恼。

投诉文章 ©著作权归作者所有
喜欢  |  0
0/200字
没有更多评论了~
悬赏问题
给科研问题设置一定金额,将更容易获得关注与回答哦~
  • 1元
  • 3元
  • 5元
  • 8元
  • 18元
  • 自定义
选择支付方式
  • 微信支付
  • 支付宝支付
  • 余额支付
Copyright © 2014-2019 晟斯医学 All Rights Reserved. 备案号:苏ICP备11037034号-5 版权所有:南京孜文信息咨询有限公司