R语言——基础学习——第五课

本文详细介绍使用R语言进行高级绘图的方法,包括各种类型的绘图符号、线条样式、颜色设置以及如何调整坐标轴范围。通过实例展示了如何利用不同类型参数绘制折线图、散点图等,并介绍了如何添加文本、标题及副标题来丰富图表信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

?plot#高级绘图函数 可以完整地绘制出一张图
?mtcars
plot(mtcars$wt)
plot(mtcars[,1:2])
plot(mtcars)
plot(mtcars$wt,mtcars$disp)
plot(mtcars$wt,mtcars$disp,type='p')
plot(mtcars$wt,mtcars$disp,type='l')
plot(mtcars$wt,mtcars$disp,type='b')
plot(mtcars$wt,mtcars$disp,type='o')

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


par(no.readonly = T)
opar<-par(no.readonly = T)
par(mfrow=c(3,3))
for (i in c('p','l','b','c','o','h','s','S','n')) {
  plot(mtcars$wt,mtcars$disp,type=i,main=paste('type',i))
}
#s 和 S 都是阶梯线 n是空图

par(opar)
?pch

#pch
plot(mtcars$wt,mtcars$disp,pch=2)
plot(mtcars$wt,mtcars$disp,pch=2,cex=3)

#折线图 lty lwd
plot(mtcars$wt,mtcars$disp,type='l')
plot(mtcars$wt,mtcars$disp,type='l',lty=3)
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3)

#col
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col='blue')
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col=8)#col 从1到8,超过1-8还是重复1-8的颜色
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col=4)
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col=12)
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col='#0000FF')
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col=rgb(0,0,1))
plot(mtcars$wt,mtcars$disp,type='l',lty=3,lwd=3,col=hsv(h=240/360,s=1,v=1))#饱和度

#xlim ylim
plot(mtcars$wt,mtcars$disp,xlim = c(2,4),ylim = c(100,400))


#文本
plot(mtcars$wt,mtcars$disp,xlim = c(2,4),ylim = c(100,400),
     main = 'Motor Trend Car Road Tests',sub = '2019-6',
     xlab='wt',ylab = 'dist')
plot(mtcars$wt,mtcars$disp,xlim = c(2,4),ylim = c(100,400),
     main = 'Motor Trend Car Road Tests',sub = '2019-6',
     ann = F)#ann=F表示去掉标签标题副标题
title(main = 'Motor Trend Car ...',sub = '2019-6',
      xlab='wt',ylab = 'dist')#低级绘图函数 再加上标签标题副标题




#homework Q1
plot(mtcars$mpg,mtcars$qsec)

#homework Q2
opar<-par(no.readonly = T)
par(mfrow=c(4,4))
for (i in c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16)) {
  plot(mtcars$mpg,mtcars$qsec,pch=i,main=paste('pch:',i))
}
par(opar)

#homework Q3  
library(readxl)
stock <- read_excel("D:/ChromeCoreDownloads/作业5/stock.xlsx")
View(stock)

#homework Q4
plot(stock$date,stock$investor_confidence_index,type = 'l',
     main = '投资者信心指数时序图',
     xlab = '时间',ylab = '投资者信心指数')

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值