上文为大家介绍的是R语言中的散点图,相信大家已经对R语言有一定的了解了,接下来小编就给大家说说关于线图与时间序列谱图。
一、给线图增加legend(图例)
legend(1,300,legend=c("Tokyo","Berlin","New York","London"),
lty=1,lwd=2,pch=21,col=c("black","red","orange","purple"),
horiz=TRUE,bty="n",bg="yellow",cex=1,
text.col=c("black","red","orange","purple"))
二、画底纹格子
rain<-read.csv("cityrain.csv")
plot(rain$Tokyo,type="b",lwd=2,
xaxt="n",ylim=c(0,300),col="black",
xlab="Month",ylab="Rainfall(mm)",
main="Monthly Rainfall in Tokyo")
axis(1,at=1:length(rain$Month),labels=rain$Month)
grid()
三、时间序列图
sales<-read.csv("dailysales.csv")
plot(sales$units~as.Date(sales$date,"%d/%m/%y"),type="l",xlab="Date",ylab="Units Sold")
四、时间刻度可读化
plot(air$nox~as.Date(air$date,"%d/%m/%Y %H:%M"),type="l",xaxt="n",xlab="Time", ylab="Concentration (ppb)",main="Time trend of Oxides of Nitrogen")
xlabels<-strptime(air$date, format = "%d/%m/%Y %H:%M")
axis.Date(1, at=xlabels[xlabels$mday==1], format="%b-%Y")
五、求出均值后画时间序列
air$date = as.POSIXct(strptime(air$date, format = "%d/%m/%Y %H:%M“,"GMT"))
means <- aggregate(air["nox"], format(air["date"],"%Y-%U"),mean,na.rm = TRUE)
means$date <- seq(air$date[1], air$date[nrow(air)],length = nrow(means))
plot(means$date, means$nox, type = "l")
六、抓取股票数据并画出趋势图
aapl<-get.hist.quote(instrument = "aapl", quote = c("Cl", "Vol"))
goog <- get.hist.quote(instrument = "goog", quote = c("Cl", "Vol"))
msft <- get.hist.quote(instrument = "msft", quote = c("Cl", "Vol"))
plot(msft$Close,main = "Stock Price Comparison",ylim=c(0,800), col="red", type="l", lwd=0.5,
pch=19,cex=0.6, xlab="Date" ,ylab="Stock Price (USD)")
lines(goog$Close,col="blue",lwd=0.5)
lines(aapl$Close,col="gray",lwd=0.5)
legend("top",horiz=T,legend=c("Microsoft","Google","Apple"),
col=c("red","blue","gray"),lty=1,bty="n")
关于R语言数据展现——线图与时间序列谱图的讲述就到这里了,上述的内容只是截取了资料中的一部分,如需获取完整的资料,可通过关注微信公众号后联系客服获取。
想要了解更多的资料、信息,可持续关注我们,我们将为大家提供有价值、有需求的材料。为大家在整理数据时省去烦恼。