R学习笔记低级绘图函数R学习笔记 | 低级绘图函数
stay是什么意思翻译
绘图函数:
(1) ⾼级绘图函数(plot()),可以画出整幅图;
(2) 低级绘图函数(point()、lines()、ablines()),在已画好的图中添加点、线。⼀、ablines()
功能:添加直线或斜线
This function adds one or more straight lines through the current plot
POSIXct是时间类型
atmosphere
wavelibrary(readxl)
stock<-read_excel('stock.xlsx')
plot(stock$date,stock$SH_closing_price,type='l',ylim=c(1500,13000))
catchup>sniffy
abline(h=3000,v=as.POSIXct('2015-01-30'),col='grey') #添加了两条直线
⼆、lines()
功能:添加图形或线都可
(A generic function taking coordinates given in various ways and joining the corresponding points with line gments.)
plot(stock$date,stock$SH_closing_price,type='l',ylim=c(1500,13000)) #上证指数
abline(h=3000,v=as.POSIXct('2015-01-30'),col='grey')
lines(stock$date,stock$SZ_closing_price,lty=2) #添加了深证指数
六级题目
⼩tip:解决图形太乱的问题
plot(stock$SH_closing_price,stock$investor_confidence_index,type='l') #这个图是乱的
#解决⽅法:给横坐标排序
stock1<-stock[order(stock$SH_closing_price),] #对图的横坐标排序
plot(stock1$SH_closing_price,stock1$investor_confidence_index,type='l')
乱图是这样的:
勺子 英文
排序以后是这样的:
画x相同,y不同的⼏条线,⽤matplot()更好写
matplot(stock$date,stock[,2:4],lty=1:3,type='l',
col='black')
三、point()
功能:添加点
(points is a generic function to draw a quence of points at the specified coordinates. The specified character(s) are plotted, centered at the coordinates.)
#给上证指数收盘价分两类。以它为x,以投资者信⼼指数为y,分别⽤三⾓和圆画出两类点
#⽅法1
stock$stock_class<-ifel(stock$SH_closing_price<3000,1,2)
stock1<-subt(stock,stock_class==1)
stock2<-subt(stock,stock_class==2) #分类结束
plot(stock1$SH_closing_price,stock1$investor_confidence_index,pch=16,
col='blue',xlim=range(stock$SH_closing_price),
ylim=range(stock$investor_confidence_index)) #画出第⼀类
points(stock2$SH_closing_price,stock2$investor_confidence_index,
mwe
pch=17,col='green') #添加进去第⼆类
职场#⽅法2
plot(stock$SH_closing_price,stock$investor_confidence_index,
col=c('blue','green')[stock$stock_class],
pch=c(16,17)[stock$stock_class]) #相当于说明了每个点是什么颜⾊,什么形状
rated r