R语言(4) plot函数介绍

目录

plot函数:

 type绘图类型

 一页多图画法

 pch点符号类型

cex控制点的大小

lty线条类型 

 lwd线条宽度

col颜色 

 xlim ylim 坐标轴取值范围

 main  sub 主副标题

xlab,ylab 标签 

plot函数:

 mtcars是一个内置的演示用的数据集,方便用户直接拿这些示例数据试验某些作图功能,下面使用mtcars作图演示。

 plot(mtcars$wt)

 plot(mtcars$wt,mtcars$disp)

 plot(mtcars)

 type绘图类型

p表示点,l表示线,b表示下划线,其他o,h,s,S

mtcars<-mtcars[order(mtcars$wt),]
plot(mtcars$wt,mtcars$disp,type='l')

 plot(mtcars$wt,mtcars$disp,type='b')

 plot(mtcars$wt,mtcars$disp,type='p')

 plot(mtcars$wt,mtcars$disp,type='o')

 plot(mtcars$wt,mtcars$disp,type='h')

 plot(mtcars$wt,mtcars$disp,type='s')

 plot(mtcars$wt,mtcars$disp,type='S')

 一页多图画法

par(mfrow=c(3,3))#三行三列
mtcars<-mtcars[order(mtcars$wt),]
plot(mtcars$wt,mtcars$disp,type='l')
plot(mtcars$wt,mtcars$disp,type='b')
plot(mtcars$wt,mtcars$disp,type='p')
plot(mtcars$wt,mtcars$disp,type='o')
plot(mtcars$wt,mtcars$disp,type='h')
plot(mtcars$wt,mtcars$disp,type='s')
plot(mtcars$wt,mtcars$disp,type='S')

 pch点符号类型

plot(mtcars$wt,mtcars$disp,pch=2)

 plot(mtcars$wt,mtcars$disp,pch=1)

 其余自己测试

cex控制点的大小

plot(mtcars$wt,mtcars$disp,pch=1,cex=1.5)

#默认是1, 1.5就是默认大小的1.5倍

lty线条类型 

par(mfrow=c(3,2))
plot(mtcars$wt,mtcars$disp,type='l',lty=1)
plot(mtcars$wt,mtcars$disp,type='l',lty=2)
plot(mtcars$wt,mtcars$disp,type='l',lty=3)
plot(mtcars$wt,mtcars$disp,type='l',lty=4)
plot(mtcars$wt,mtcars$disp,type='l',lty=5)
plot(mtcars$wt,mtcars$disp,type='l',lty=6)

 lwd线条宽度

plot(mtcars$wt,mtcars$disp,type='l',lty=1,lwd=0.5)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,lwd=2)

 

col颜色 

par(mfrow=c(3,4))
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col='blue')
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col='red')
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=1)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=2)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=3)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=4)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=5)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=6)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=7)
plot(mtcars$wt,mtcars$disp,type='l',lty=1,col=8)

#直接使用颜色名字或者数字1-8

#或者使用十六进制颜色或rgb函数

 xlim ylim 坐标轴取值范围

plot(mtcars$wt,mtcars$disp,type='l',xlim=c(3,4),ylim=c(300,400))

 main  sub 主副标题

plot(mtcars$wt,mtcars$disp,type='l',lty=1,main='qq折线图',sub='2022/10/1')

xlab,ylab 标签 

plot(mtcars$wt,mtcars$disp,type='l',lty=1,main='qq折线图',sub='2022/10/1',xlab='x轴标签',ylab='y轴标签')

  • 7
    点赞
  • 56
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

面咋了

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值