未明学院14天打卡笔记 Day5

#基础绘图函数
?plot
?par##全局的函数,
plot(mtcars$wt,mtcars$disp)
plot(mtcars$wt)
plot(mtcars)
plot(mtcars$wt,mtcars$disp,type = 'p')
plot(mtcars$wt,mtcars$disp,type = 'l')
order(mtcars$wt)##对mtcars中的wt进行从小到大的排序,返回的是排序之后wt在mtcars中行的坐标
mtcars<-mtcars[order(mtcars$wt),]
mtcars##可见mtca中的wt是按照从小到大的顺序排列的
plot(mtcars$wt,mtcars$disp,type = 'l') ##可见折线图有一定的规律了
plot(mtcars$wt,mtcars$disp,type = 'b')
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))#注意显示在一张图上了
plot(mtcars$wt,mtcars$disp,type = 'l')
plot(mtcars$wt,mtcars$disp,type = 'b')
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')##继续运行,会在后面补满图
plot(mtcars$wt,mtcars$disp,type='b')

##右下框点击‘扫把’可以把三行三列的框恢复成单页

#pch参数:0,方框;2,三角形
plot(mtcars$wt,mtcars$disp,type='b',pch=0)
plot(mtcars$wt,mtcars$disp,type='b',pch=2)

#cex,控制点的大小
plot(mtcars$wt,mtcars$disp,type='b',pch=2,cex=0.5)

#lty,画线图的时候指定线的类型
plot(mtcars$wt,mtcars$disp,type='l',lty=1)
plot(mtcars$wt,mtcars$disp,type='l',lty=2)

##lwd,控制线条的大小
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2)

#col,控制颜色
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='blue')
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col=4) #只能1-8
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='#0000FF')##十六进制
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col=rgb(red=0,green=0,blue=1))

##xlim ylim
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='blue',xlim = c(3,4),ylim = c(200,300))

#main,标题
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='blue',main='wt和disp的折线图')
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='blue',main='wt和disp的折线图',sub='2019-9-21')

#xlab,ylab给x轴和y轴加上标签
plot(mtcars$wt,mtcars$disp,type='l',lty=2,lwd=2,col='blue',main='wt和disp的折线图',sub='2019-9-21',xlab = '重量',ylab = '迪斯')

# 作业5 ---------------------------------------------------------------------
#1、
plot(mtcars$mpg,mtcars$qsec,pch=8)

#2、
library(readxl)
stock<-read_excel('E:/桌面快捷文件存放/A207/2019年暑假/任务2/未明学院/未明学院作业/stock.xlsx')
View(stock)

#3、
plot(stock$date,stock$investor_confidence_index,type = 'l',main='投资者信心指数时序图')

猜你喜欢

转载自www.cnblogs.com/chayibaishanlqy/p/11574859.html
今日推荐