前面的博客我們詳細介紹了plot()函數(shù)的使用辜窑,他很關(guān)鍵,很重要寨躁,如果您不了解穆碎,那么你可能不知道我再說什么。現(xiàn)在我們基于它來給大家分享一下折線圖的繪制职恳。
注:需要數(shù)據(jù)的可以發(fā)簡信找我要所禀,方面,,色徘,恭金,,褂策,横腿,
#加載數(shù)據(jù)集
library(readxl)
stock = read_excel("./stock.xlsx")
實驗一:繪制時間-收盤價的折線圖
image.png
abline(h=3000,v=as.POSIXct("2020-05-15"),lty=3,col="red")
#不能單獨使用,需要依賴之前的圖形斤寂,作用是在圖形上面繪制一條水平直線
#h代表水平耿焊,V代表垂直。
image.png
lines(stock$date,stock$SZ_closing_price,lty=4,col="blue")#也不能單獨使用扬蕊,需要依賴之前的圖形搀别,作用是在原來的圖像上面在繪圖!
#查看范圍
range(stock$SZ_closing_price)
image.png
在這里我們發(fā)現(xiàn)上面的圖像沒有完全顯示尾抑,這就是[比例尺的]的問題了歇父!使用range()
image.png
plot(stock$date,stock$SH_closing_price,type='l',ylim = range(stock$SZ_closing_price)#設(shè)置y軸的比列尺,以便圖像可以完全顯示)
abline(h=3000,v=as.POSIXct("2030-05-15"),lty=3,col="red")
#不能單獨使用再愈,需要依賴之前的圖形
lines(stock$date,stock$SZ_closing_price,lty=4,col="blue")
#查看范圍
range(stock$SZ_closing_price)
image.png
實驗三 投資者的信心指數(shù)
#數(shù)據(jù)的排序
stock1 = stock[order(stock$SH_closing_price),]
plot(stock1$SH_closing_price
,stock1$investor_confidence_index
,type='l')
image.png
matplot 一個數(shù)據(jù)集繪制多列榜苫,但是一般不使用,不過還是很方便的
matplot(stock$date#x軸
,stock[,2:4]#以2,3,4列為Y軸繪制屬性的圖形
,lty=1:3
,type='l'
,col=c('blue','green','red'))
image.png